#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13

    Rewriting a domain's specific .html requests


    Here it is: rewrite of superhost.gr's specific .html requests.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.superhost\.gr$ [OR]
    RewriteCond %{HTTP_HOST} ^superhost\.gr$
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]


    I just need a way for .htaccess to grab NOT ONLY the basename of the html file being requested BUT it's absolute path too.

    Please help me ADD it and if you see something wrong the way i have written it up until now, perhaps a better way to write this, please alter the code too.

    Thank you very much.
    What is now proved was once only imagined!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,142
    Rep Power
    9398
    You can stick the REQUEST_FILENAME in there.
    Code:
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=%{REQUEST_FILENAME} [L,PT,QSA]
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    Originally Posted by requinix
    You can stick the REQUEST_FILENAME in there.
    Code:
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=%{REQUEST_FILENAME} [L,PT,QSA]
    But that would be the same as:

    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]

    No?!
    What is now proved was once only imagined!
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,142
    Rep Power
    9398
    No. The REQUEST_FILENAME is the full, absolute, filesystem path to the requested file while $1 is just what the RewriteRule matched.
    If the URL is /path/to/file.html then $1="path/to/file.html" while REQUEST_FILENAME="/home/nik/public_html/path/to/file.html" (or whatever).
  8. #5
  9. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    Originally Posted by requinix
    No. The REQUEST_FILENAME is the full, absolute, filesystem path to the requested file while $1 is just what the RewriteRule matched.
    If the URL is /path/to/file.html then $1="path/to/file.html" while REQUEST_FILENAME="/home/nik/public_html/path/to/file.html" (or whatever).
    Thank you, i have understtod that now!

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.superhost\.gr$ [OR]
    RewriteCond %{HTTP_HOST} ^superhost\.gr$
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=%{REQUEST_FILENAME} [L,PT,QSA]
    Can this be written any better though than it already is? perhaps by removing 1 line of condition for superhost.gr ?
    What is now proved was once only imagined!
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,142
    Rep Power
    9398
    Sure: you can make the "www." optional.
    Code:
    RewriteCond %{HTTP_HOST} ^(www\.)?superhost\.gr$
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=%{REQUEST_FILENAME} [L,PT,QSA]

IMN logo majestic logo threadwatch logo seochat tools logo