Forum Moderators: phranque

Message Too Old, No Replies

Question about RewriteRule

.htaccess

         

enigma1

8:03 pm on May 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using a simple mapping to process html pages via a single php script so within my .htaccess I have:


Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*).html$ root.php?%{QUERY_STRING}

At the php level I am relying on the REQUEST_URI parameter to identify the typed-in URL.

After testing this with few servers I run in a case where the rule didn't work. After investigation at the php level, I noticed the REQUEST_URI server parameter wasn't set to the originally typed url but instead to root.php. I then dumped the server parameters and noticed none of them contained a single reference to the original typed url in this case.

So I am suspecting that particular server must have a script to do a redirect on that rewriterule or something? (have limited server access so I cannot see the logs). Anyways to get around it I changed the rule to pass the requested page to cover such cases like:


RewriteRule ^(.*).html$ root.php?$1.html&%{QUERY_STRING}

And then added some additional code to process it at the php level and this works...

My question is, should I do all this extra processing, or should I rely on the host to have their scripts maintain the REQUEST_URI? Are they out of spec? Or should I change the .htaccess code?

jdMorgan

10:45 pm on May 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ask them if they have set AcceptPathInfo on. If so, it may grab any non-existent file request, strip the requested URL back to the longest URL-path that resolves to a file that actually exists, and put the rest into the variable PATH_INFO.

Jim

enigma1

12:12 am on May 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jim, when I tried

AcceptPathInfo On

in .htaccess I got a 500. I am going to ask them about it, but I tried a bunch of other things reading this forum and can't figure out what's going on. I checked the rewrite rule from here
[httpd.apache.org...]
but couldn't see a direct reference that the REQUEST_URI can have different content than the one typed in. Says pretty much the same as in the php manual.

From your experience, is this something I should expect to see often, or is it a rare case? I am asking, as this is for a contribution for oscommerce where many people may use it and I want to have something as compatible as possible, with different server configuration settings.

jdMorgan

12:49 am on May 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may or may not be allowed to modify the setting, but if it is set, you will likley find that the "missing" part of the URL has been moved into the PATH_INFO variable.

In which case, you'd want to turn AcceptPathInfo Off as an experiment to see if thst affects your symptoms.

Or it could be some other problem...

> From your experience...

My experience is not all that great. I'm just a volunteer moderator here, answering a few questions that I can answer, and a few that I might be able to help with...

So, I don't know if the problem is common or not. I've seen several threads here on seemingly-related troubles, though. AcceptPathInfo is great if you need it and want it, but like several other Apache features such as MultiViews, its effects can be 'bad' if you don't want them, need them, or expect them.

Jim

enigma1

2:13 pm on May 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, my best bet will be to add as much information as possible with the module's documentation and comments to the .htaccess for the various options.

I have no longer access to that server to test the AcceptPathInfo off case, but I can emulate and process the PATH_INFO parameter locally.

One other thing I tested was to conditionally do the extra processing if the REQUEST_URI points to the script that handles the html requests.

Again thanks for the information, if I find something else about it, I will post again to this thread.