Rewrite with & and ? won't redirect

Discuss practical ways rearrange URLs using mod_rewrite.

Rewrite with & and ? won't redirect

Postby sharingsunshine » Wed Aug 12, 2009 10:27 am

Hello,

I am having problems with removing the appended query statement in the following rewrite:

http://www.anydomain.com/error_message. ... 1d4ce70bb3

RewriteCond %{REQUEST_URI} ^error_message\.php$
RewriteCond %{QUERY_STRING} ^product_disabled(.*)$
RewriteRule ^.*$ http://www.anydomain.com/index.html? [R=301,L]

I get many of these requests for non existent files and my 404 program sends me an email on all of the requests that are bad. I just want to capture this kind of request and redirect it to another location.

Please tell me how to accomplish this redirect.

Thanks,

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Wed Aug 12, 2009 11:19 am

The REQUEST_URI variable would contain "/error_message.php". Why aren't you using the RewriteRule?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?product_disabled(&.*)?$ [NC]
RewriteRule ^error_message\.php$ http://www.anydomain.com/index.html? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sharingsunshine » Wed Aug 12, 2009 5:10 pm

Hello,

Thanks for the code but it still is appending the query to the url.

Here is what I used:

RewriteCond %{QUERY_STRING} ^(.*&)?product_disabled(&.*)?$ [NC]
RewriteRule ^error_message\.php$ http://www.anydomain.com/index.html? [R=301,L]


Originally, I had used the rewrite rule and it didn't work. So, I saw an example that used REQUEST_URI instead. But I now see why RewriteRule would be better in this case.
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Fri Aug 14, 2009 12:59 pm

Have you cleared your browser's cache?
How are you testing this? Are you visiting a URL in your browser (eg. /error_message.php?product_disabled&xid=abc)?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sharingsunshine » Fri Aug 14, 2009 7:47 pm

Yes, I have cleared the cache and I am testing with a url. Here is the url:
http://www.healthypetcorner.com/error_m ... 1d4ce70bb3

Do I need to do something else because of the &?

Thanks,

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Sun Aug 16, 2009 7:08 am

Do you have any other mod_rewrite?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sharingsunshine » Sat Aug 22, 2009 1:27 pm

You're correct it was something else causing the conflict. When I stripped everything out of the .htaccess file but your pattern, it worked.

This has been a great help. Thanks so much.

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 22 guests

cron