1

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)

Andrew
  • 2,691
  • 6
  • 31
  • 47
  • I see no reason of RewriteConds there. You make rewrite, not redirect `RewriteRule ^/(.+)$ /${vanURL:$1|$1} [L]` – Deadooshka Apr 13 '15 at 21:21

1 Answers1

1

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks but this still doesn't work for me. Nothing happens. It's like it's not being read. If you're sure this should work, can you provide any debugging tips? – Andrew Apr 13 '15 at 22:25
  • That would be awesome - FYI, I tried this example (copy+paste): http://www.onlamp.com/pub/a/apache/2005/04/28/apacheckbk.html and it worked. – Andrew Apr 13 '15 at 22:42
  • Hey thanks - the last line doesn't work for me but this did: RewriteRule ^/(.*) /${vanURL:$1} [PT]. However, neither line seems to consider subfolders. What if I wanted to also consider the entire folder recursively? For example, "some_folder/anything/index.html" also redirect to "another_folder/anything/index.html"? – Andrew Apr 14 '15 at 10:00
  • So do you want to match folder `some_folder/anything` from this URL `http://example.com/some_folder/anything/index.html` ? – anubhava Apr 14 '15 at 10:03
  • I want it to basically rewrite "somefolder/*.*" to "another_folder/*.*". This should also consider the basic root folder "somefolder" too. – Andrew Apr 14 '15 at 10:14