I have a about 25000 urls from my old site that have abc in the url.
I want to use 3 DBM files in my apache conf.
The goal is if the URL does not contain abc ie. http://example.com/1234.htm
then I do not want the abcredirects.DBM file to be look at.
If the URL does contain abc ie. http://example.com/abc1234.htm
then I only want the abcredirectsDBM file to be look at.
I am trying to use an if statement in my Apache however anytime I use the <If>
block whatever I put inside seems to be ignored.
I have changed the <If "%{REQUEST_URI} =~ m#^abc#">
line many different ways but it does not matter. If i remove the <if>
block all redirects works as expected.
Why is my <if>
block being ignored? There is no error and according to the logs http://example.com/abc1234.htm
(i am assuming) is not evaluating to true so I am not sure what else to check.
[root@mail conf]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jun 27 2018 13:48:59
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteMap abcredirects "dbm:/etc/httpd/conf/dbm/abcredirects.dbm"
<If "%{REQUEST_URI} =~ m#^abc#">
RewriteCond ${abcredirects:$1} !=""
RewriteRule ^(.*) /${abcredirects:$1} [R=301,L]
</If>
RewriteMap shortalias "dbm:/etc/httpd/conf/shortalias.dbm"
RewriteCond ${shortalias:$1} !=""
RewriteRule ^(.*) /${shortalias:$1} [R=301,L]
</IfModule>
<VirtualHost *:80>
DocumentRoot /var/www/sites/me
ServerName example.com
DirectoryIndex index.htm
Options +FollowSymLinks
RewriteEngine On
RewriteOptions Inherit
RewriteMap otherredirects "dbm:/etc/httpd/conf/otherredirects.dbm"
RewriteCond ${otherredirects:$1} !=""
RewriteRule ^(.*) /${otherredirects:$1} [R=301,L]
</VirtualHost>
Serverfault questions I have seen and tried: