I'm trying to get MapRewrite working for some vanity urls but I'm just not having any luck. I don't get errors, it just doesn't seem to work (redirect).
Here's the code I put in my vhost.conf:
RewriteEngine On
RewriteMap vanURL txt:/var/www/vhosts/myconditions.txt
RewriteCond ${vanURL:$1|not-found} ^(.+)$
RewriteCond %1 ~^not-found$
RewriteRule ^/(.*) /${vanURL:$1|/$1} [L]
What I'm looking to do is to determine if "www.mydomain.com/some_folder" exists. If it doesn't, look in "myconditions.txt" for "some_folder" and redirect to the corresponding location.
Here's an example of MyConditions.txt
some_folder another_folder
some_folder_two another_folder_two
Visiting www.mydomain/some_folder is simply a dead link.
Can anyone point me in the right direction?
(Note that I did test putting garbage in my Vhost.conf and .htaccess to ensure the files are being read)
You cannot use %1
in LSH of the condition, use a negative lookahead like this:
RewriteEngine On
RewriteMap vanURL txt:/var/www/vhosts/myconditions.txt
RewriteRule ^/([^/]+)(/.*)?$ /${vanURL:$1}$2 [PT]