Topic: RewriteMap and RewriteRule and querystrin
|

|
| Author |
|
cameron_ca Newbie

Joined: 25 June 2010 Location: United States
Online Status: Offline Posts: 2
|
| Posted: 25 June 2010 at 4:50pm | IP Logged
|
|
|
I've got a map file that looks like this:
index.php?id=100 /newpage1
oldpage.htm?site=a /newpage2
contact.php /newpage3
The rule in use is:
RewriteMap redirects301 txt:d:/WEBROOT/config/redirects301.txt [NC]
RewriteCond ${redirects301:$1|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^(.+)$ ${redirects301:$1} [NC,L,R=301]
On this site I have access to the httpd.conf file and the customer has access to the redirects301.txt file. My goal is
for the end user to be able to set their own redirects without needing access to the primary config file. This works
fine... almost. The problem is whenever the URL contains a querystring; the redirect doesn't happen. I'm familiar
with the use of RewriteCond %{QUERY_STRING} when you know what the querystring might contain ahead of time, but in this
case all I know is contained in What I really want to do is just completely ignore the ? and treat it as one entire
URL.
Any ideas?
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10483
|
| Posted: 29 June 2010 at 5:53am | IP Logged
|
|
|
Please try to fix your config like this:
RewriteMap redirects301 txt:d:/WEBROOT/config/redirects301.txt [NC]
RewriteCond %{QUERY_STRING} ^(.+)?$
RewriteCond ${redirects301:$1(?%1\?%1)|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^(.+)$ ${redirects301:$1(?%1\?%1)}? [NC,L,R=301]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
dooza Newbie

Joined: 06 April 2009 Location: United Kingdom
Online Status: Offline Posts: 32
|
| Posted: 08 July 2010 at 5:16am | IP Logged
|
|
|
This is exactly what I was looking for, you have saved me hours of work, thank you very much!
Dooza
|
| Back to Top |
|
| |
cameron_ca Newbie

Joined: 25 June 2010 Location: United States
Online Status: Offline Posts: 2
|
| Posted: 08 July 2010 at 8:02am | IP Logged
|
|
|
Yep, worked for me too!
|
| Back to Top |
|
| |
TonyJ Newbie

Joined: 29 July 2010 Location: Belgium
Online Status: Offline Posts: 1
|
| Posted: 29 July 2010 at 11:19am | IP Logged
|
|
|
Anton wrote:
Please try to fix your config like this:
RewriteMap redirects301 txt:d:/WEBROOT/config/redirects301.txt [NC]
RewriteCond %{QUERY_STRING} ^(.+)?$
RewriteCond ${redirects301:$1(?%1\?%1)|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^(.+)$ ${redirects301:$1(?%1\?%1)}? [NC,L,R=301] |
|
|
Thanks Anton for sharing with us your solution. I tested your solution and it worked for me too but not for "dir1/dir2/?Test=100" !
Small question how do I need to change it for it also to work with
dir1/dir2/?Test=100 /newdir1/filename100 dir3/?T=UK /newdir3/filename2
In other words what if QUERY_STRING is directly preceded by a / how do we need to change ReWriteCond ?
Thanks already for your input
Tony
Edited by TonyJ - 29 July 2010 at 11:21am
__________________ Tony J
Creations.be
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10483
|
| Posted: 30 July 2010 at 3:52am | IP Logged
|
|
|
Please try to fix it like this:
RewriteMap redirects301 txt:d:/WEBROOT/config/redirects301.txt [NC]
RewriteCond %{QUERY_STRING} ^(.+)?$
RewriteCond ${redirects301:$1(?%1\?%1)|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule ^(.+?)/?$ ${redirects301:$1(?%1\?%1)}? [NC,L,R=301]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
|
|
If you wish to post a reply to this topic you must first login
If you are not already registered you must first register
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You can vote in polls in this forum
|