Forum Moderators: phranque

Message Too Old, No Replies

Rewrite rule for nondynamic to a dynamic page

         

apkeimel

6:20 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



Hi there -

I'm attempting to redirect a page location to the same page location + some URL parameters. Specifically:

^/catalog/hgindex.html should be redirected to
^/catalog/hgindex.html?ct=hg

When I attempt to add the rewrite rule to httpd.conf, I get an endless loop of the page trying to load. I've tried different incantations of the rewrite rule, but I'm missing something. WOuld someone graciously lend a hand?

Thank you.
Alisa

jdMorgan

7:23 pm on Feb 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



apkeimel,

Welcome to WebmasterWorld [webmasterworld.com]!

You'll need to use a RewriteCond directive ahead of your RewriteRule to test the query string to make sure it is blank before you rewrite it. Otherwise, your server may loop as you describe.
The general form would be:


RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/catalog/hgindex\.html$ /catalog/hgindex.html?ct=hg [L]

See the Apache mod_rewrite documentation [httpd.apache.org] for details.

Jim

apkeimel

1:32 pm on Feb 19, 2004 (gmt 0)

10+ Year Member



Jim -

Thanks for the help. Attempted your solution and at this point, the page doesn't reload indefinitely anymore, but it also is not forwarded. It just sits there upon a reload. I'll have to check the apache docs more fully and play with it some more.

Sincerely,
Alisa

apkeimel

2:35 pm on Feb 19, 2004 (gmt 0)

10+ Year Member



I figured it out :)

This works:
RewriteCond %{QUERY_STRING} ^$
RewriteRule /catalog/hgindex.html$ /catalog/hgindex.html?ct=hg [L,R]

But I had to place it before another very specific set of rewrite rules in the httpd.conf file, so that this rule would be executed first - I originally had the rule at the end of the file, and the other rewrite rule that is in place was overriding it.

Thanks again for all your help. And thank you for your time and assistance. I see that you get a LOT of traffic here and that you personally respond to each post. That's a lot of effort. Thanks for your direction. It was enough for me to figure it out the rest on my own.

Alisa

jdMorgan

3:37 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want search engines to follow your redirects, be sure to use [R=301,L]. The default behaviour for [R,L] is to generate a 302-Moved Temporarily response, and that can cause problems with search engines. It is also preferred to include the full domain name and path (e.g. http://www.yourdomain.com/catalog/hgindex.html?ct=hg) in the substitution string when using any [R] flag.

Jim