Need Simple .htaccess Help!

Discussion in 'Programming' started by Corwin, Aug 21, 2009.

  1. #1
    I need some .htaccess help. If the browser URL path is one of the following:
    http:/www.mydomain.com/path1/path2/.../final
    http:/www.mydomain.com/path1/path2/.../final/
    http:/www.mydomain.com/final
    http:/www.mydomain.com/final/

    I need to test if "final", the last path info, contains a period "." anywhere in it and if so, go to handler.asp. I don't care if path1, path2, path3 etc. contains a period. Also, /final may or may not contain a trailing / (as in /final/) and that is a don't care.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} (something)
    RewriteRule . /.handler.asp [L]


    Can someone tell me what (something) should be?

    Thanks!

    Added later:
    I don't want the rule to fire if the filename & path point to an EXISTING file on the server
     
    Last edited: Aug 21, 2009
    Corwin, Aug 21, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this: (untested)

    RewriteEngine On
    RewriteRule [^\/]+\.[^\/]*/?$ handler.php
    Code (markup):
     
    premiumscripts, Aug 21, 2009 IP
  3. Corwin

    Corwin Well-Known Member

    Messages:
    2,438
    Likes Received:
    107
    Best Answers:
    0
    Trophy Points:
    195
    #3
    @premiumscripts, I don't want the rule to fire if the filename & path point to an EXISTING file on the server (I just modified my original post to reflect that). Does your script do that?
     
    Corwin, Aug 21, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, just add these two original rules you had:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    -f means don't match a file
    -d means don't match a dir (though this one isn't really necesary obviously)
     
    premiumscripts, Aug 21, 2009 IP
  5. Corwin

    Corwin Well-Known Member

    Messages:
    2,438
    Likes Received:
    107
    Best Answers:
    0
    Trophy Points:
    195
    #5
    I can't get your code recommendation to work.
    I tried this for my .htaccess (your line is highlighted in red):

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    [COLOR="red"]RewriteRule [^\/]+\.[^\/]*/?$ HasAdot.asp[/COLOR]
    RewriteRule . NoDot.asp [L]
    Code (markup):
    Regardless of the URL I enter in the browser, NoDot.asp is always run. Even when I enter HasAdot.asp as the URL, NoDot.asp is always run!

    What am I doing wrong?
     
    Corwin, Aug 22, 2009 IP