Rewrite map to substitute urls

New to mod_rewrite? This is a good place to start.

Rewrite map to substitute urls

Postby swebb » Thu Sep 03, 2009 9:45 am

Ok, I've got rules like this now:

Code: Select all
RewriteMap txtmap txt:/etc/httpd/conf/urlmap.txt
RewriteCond ${txtmap:$1|not_found} ^(.+)
RewriteCond %1 !^not_found$
RewriteRule ^/(.*) /%1 [R=301,L]


My urlmap.txt file looks like:

Code: Select all
AAA   BBB


This works:
http://machine/AAA --> http://machine/BBB

This doesn't:
http://machine/AAA/anything --> http://machine/BBB/anything

What do I need to change to get the stuff after the 'AAA' to be caught and appended to the rewritten URL?
swebb
 
Posts: 1
Joined: Thu Sep 03, 2009 9:40 am

Postby richardk » Thu Sep 03, 2009 5:27 pm

The problem is
Code: Select all
^/(.*)

makes $1 = AAA/anything.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteMap txtmap txt:/etc/httpd/conf/urlmap.txt

RewriteCond ${txtmap:$1|not_found} ^(.+)$
RewriteCond %1 !^not_found$
RewriteRule ^/([^/]+)(/.*)?$ /%1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 32 guests

cron