Wednesday, August 5, 2009

Apache modules question?

My web hosting company supports mod_rewrite. I tried using this snippet:



RewriteEngine on



RewriteRule /([a-z0-9_-]*)\.aspx? /main.php?sec=$1 [PT]



so if the request is for %26quot;foo.asp%26quot; or %26quot;foo.aspx%26quot;, the URL will be rewritten as %26quot;main.php?sec=foo%26quot;. And this works exactly as expected on their server.



I tried to set something similar up on my (Debian -- with Apache 2.0.something, not quite exactly the same as my web host) laptop, putting those lines in a .htaccess file in my public_html directory. But when I ask for %26quot;http://localhost/~lucy/foo.asp%26quot;, it%26#039;s actually looking for a file named foo.asp, not rewriting it. (I checked, by creating a file called foo.asp.)



I checked my configuration, and both mod_userdir and mod_rewrite are enabled, but it stubbornly refuses to work.



What%26#039;s wrong?



(NB. I had to email my bit of config snippet to one of the techies at the hosting co. for them to install it. Could they have spootted a mistake and fixed it without telling me?)



Apache modules question?





I%26#039;m no web server expert, but I have to ask - what is the exact URL structure that you use to request foo.asp from your hosted web site? Does it include a path from the document root?



I ask because in the example you show for your laptop, you are not requesting from the web server document root, you are requesting from the %26quot;~lucy%26quot; sub-directory of the web server document root.



Also, I tried reading Apache%26#039;s instructions on this (see link below). I did not see any rule written exactly like yours. All RewriteRules have a space and then a carrot symbol (%26#039;^%26#039;) before the forward slash.



I%26#039;d say it%26#039;s very likely that they fixed your code before deploying it, you may want to ask them what they did.



**ADDITIONAL INFO: Did you check the gray %26#039;Attention%26#039; message area near the very top of the page at the link I provided? It says in part %26quot;Depending on your server-configuration it can be necessary to slightly change the examples for your situation, e.g. adding the [PT] flag when additionally using mod_alias and mod_userdir, etc. Or rewriting a ruleset to fit in .htaccess context instead of per-server context.%26quot;



Note that the [PT] flag may be necessary when using mod_userdir.

No comments:

Post a Comment