The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> Apache Development
|
general - Rewriting a domain's specific .html requests
Discuss Rewriting a domain's specific .html requests in the Apache Development forum on Dev Shed. Rewriting a domain's specific .html requests Apache Development forum discussing HTTP Server general topics, configuration, and modules. Apache is an open source web server that runs on multiple platforms.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 18th, 2013, 01:04 PM
|
 |
Contributing User
|
|
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,004
Time spent in forums: 3 Days 12 h 52 m 42 sec
Reputation Power: 11
|
|
|
general - 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!
|

January 18th, 2013, 02:08 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
You can stick the REQUEST_FILENAME in there.
Code:
RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=%{REQUEST_FILENAME} [L,PT,QSA]
|

January 18th, 2013, 02:56 PM
|
 |
Contributing User
|
|
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,004
Time spent in forums: 3 Days 12 h 52 m 42 sec
Reputation Power: 11
|
|
Quote: | 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?!
|

January 18th, 2013, 03:50 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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).
|

January 18th, 2013, 03:57 PM
|
 |
Contributing User
|
|
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,004
Time spent in forums: 3 Days 12 h 52 m 42 sec
Reputation Power: 11
|
|
Quote: | 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 ?
|

January 18th, 2013, 04:24 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
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]
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|