RewriteMap problem in .htaccess

.htaccessrewritemap

I need to redirect URLs of the form subpage.php?sid=123 to named pages.

subpagemap.txt exists in the root and contains just the following delimited by Unix line endings \n:

1 a
2 b
3 c

The .htaccess is as follows:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteMap subpagemap txt:subpagemap.txt
RewriteCond %{THE_REQUEST} subpage\.php\?sid=([0-9]*)
RewriteRule ^.*$ ${subpagemap:%1|home}? [R=301,L,NC]

The problem is that I'm getting a 500 Internal Server Error.

When I comment out line 4 of the .htaccess, line 5 works fine and I get redirected to the default map – /home, which suggests it's the map file that's the problem.

As soon as I put the RewriteMap line back in, I get a 500 Internal Server error. I don't have access to the server logs and RewriteLog doesn't seem to work at all.

I have also tried the following substitutions one by one and together to try to isolate the problem:

RewriteMap subpagemap txt:/subpagemap.txt
RewriteCond %{THE_REQUEST} subpage\.php\?sid=([0-9]*)
RewriteRule ^.*$ /${subpagemap:1|home} [R=301,L,NC]

Any ideas what could be the problem?

Best Answer

Actually, even if the servers supports it, the problem is that you are trying do define the RewriteMap in a per-directory context (e.g. in .htaccess file), which is not allowed: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteMap

Move the definition to server or virtual host configuration, and it should work.

I still realize you probably have figured it out in a year and a half :)

Related Topic