homepage Welcome to WebmasterWorld Guest from 54.166.39.179
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
REQUEST URI issues
phpmaven

10+ Year Member



 
Msg#: 3706697 posted 9:32 pm on Jul 24, 2008 (gmt 0)

I have the following in my httpd.conf file:

*****************
RewriteCond %{query_string} !^AW= [NC]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.bluewidgets\.com [NC]
RewriteRule ^(.*)$ [bluewidgets.com...] [R=301,L]

RewriteRule ^product_pages/(.*).html /store_pages/buildpage.html?&%{QUERY_STRING}
*****************

The first part of my rewrite rules is to redirect any requests that are not directed to www.bluewidgets.com to be redirected to www.bluewidgets.com, and that works fine. Then the second part redirects any page that starts with "/store_pages/" followed by whatever and ending with ".html". The page that is being redirected to is a PHP script which parses out part of the REQUEST_URI to generate a product page on the fly. So if there is a request for "/store_pages/12345.html" it will get redirected to "/store_pages/buildpage.html" which will look at the REQUEST-URI which will be "/store_pages/12345.html" and will take the appropriate action.

Everything works fine, except that if the request that comes in has "AW=" in the query string, then I don't want to redirect the domain to "www.bluewidgets.com" I want to just leave it as is. That also works fine except that the REQUEST_URI that is passed to the PHP script is not "/store_pages/12345.html" any longer but is "/store_pages/buildpage.html"

Sorry for being so long winded but the bottom line is like this:

The following request passes REQUEST_URI ("/store_pages/12345.html") as the REQUEST_URI to my PHP script:

[bluewidgets.com...]

The following passes ("/store_pages/buildpage.html") as the REQUEST_URI to my script:

[greenwidgets.com...]

What is baffling to me as that in both the above cases the domain redirect part of my rewrite code is getting bypassed since in the first case the domain is already "www.bluewidgets.com" and in the second case the "AW=" is present in the query string and the code is bypassed.

I know that the first four lines of my rewrite are creating the problem because if I comment them out both requests pass ("/store_pages/12345.html") as the REQUEST_URI.

Any ideas?

Thanks,

Mark

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3706697 posted 9:47 pm on Jul 24, 2008 (gmt 0)

Not clear... Your second rule (as posted) rewrites URLs beginning with "product_pages" not "store_pages". Therefore, it would have no effect on the test URLs you describe.

While this is likely a problem of an inaccurate posted example, it also prevents any diagnosis of the problem.

Jim

phpmaven

10+ Year Member



 
Msg#: 3706697 posted 10:02 pm on Jul 24, 2008 (gmt 0)

I'm sorry, yes that was a mistake in my example. That should have been:

The following request passes "/product_pages/12345.html" as the REQUEST_URI to my PHP script:

[bluewidgets.com...]

The following passes "/store_pages/buildpage.html" as the REQUEST_URI to my script:

[greenwidgets.com...]

Again, in both cases the first 4 lines of my rewrite code are not executing, so I can't figure out why commenting them out would solve the problem.

Mark

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3706697 posted 10:53 pm on Jul 24, 2008 (gmt 0)

> Again, in both cases the first 4 lines of my rewrite code are not executing, so I can't figure out why commenting them out would solve the problem.

It solves the problem because the first four lines *are* executing. So, now we need to figure out why...

Please review your example URLs and the code very carefully, because they've got to be 100% accurate and ---more to the point-- internally consistent in order to figure this out.

Your 2nd rule does not rewrite to "product pages" it rewrites to "store page", so there is still a consistency problem here... Please re-work your example code and example URLs, and re-post.

The most likely cause is that the second rule is rewriting the script URL to itself recursively. This is not based on your examples, but rather on problems seen in this forum. The RewriteRule pattern must differ from the substitution path to prevent this, or additional RewriteConds must be added to serve as "loop stoppers."

Furthermore, in a .htaccess context, mod_rewrite itself is recursive. That is, if any Rewrite is invoked, mod_rewrite processing is restarted from the top. Therefore, either the rules must all be mutually-exclusive, or steps must be taken in any rules that are not mutually-exclusive to stop unexpected recursion and "infinite loops."

In odd cases like this, it is often helpful to use a server headers checker to look for unexpected redirects. I like the "Live HTTP Headers" add-on for Mozilla/Firefox.

It is also often useful to examine the server error logs for signs of recursion or other problems.

Jim

phpmaven

10+ Year Member



 
Msg#: 3706697 posted 11:32 pm on Jul 24, 2008 (gmt 0)

Thanks Jim,

You were right of course. I forgot that when the url is rewritten it runs through the rules again and then the second time the query string changes. That's a great tip about "Live HTTP Headers", that's very helpful. I will be able to figure it out now.

Thanks,

Mark

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3706697 posted 11:48 pm on Jul 24, 2008 (gmt 0)

OK.

Couple of comments: For portability, stick to the conventions -- %{QUERY_STRING} -- all caps. And I'm not sure why you'd want you query string to start with an ampersand -- ampersands are only required as delimiters between name/value pairs.

RewriteRule patterns in httpd.conf should start with a slash, in .htaccess, no slash (since the URL-path is "localized" in .htaccess).

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved