2

I try to use Apache mod_rewrite to redirect some pages on my customer's website to the homepage. The .htaccess file is the following:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^environment/teach-your-kids-to-go-green/(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/event\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/films\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/lastcomm\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/join\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^capturenature(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/blog\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^capturenatur(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/roadtomecca\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^capturenature/(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^shopping/engagement-rings-for-men/(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/thecallhome\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteRule ^a3ff/stateofthings\.html(.*) [DOMAINNAME]/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 

For some reason, this rewrite rule - RewriteRule ^a3ff/(.*) [DOMAINNAME]/$1 [R=301,L] - doesn't work on the production server. It does work on my development server, however. When I use RewriteRule ^a3fff/(.*) DOMAINNAME/$1 [R=301,L], for example (one character appended), it works perfectly. It's probably the strangest .htaccess problem I've ever seen. Can anyone help me?

1 Answer 1

3

What are you trying to accomplish?

The way you use (.) you can (and have to) only type exactly one character. For example:

http://example.com/a3ff/X => http://domainname/X http://example.com/a3ff/ => Not matched by any rule http://example.com/a3ff/ABC => http://domainname/A 

What you want is probably more like

RewriteRule ^a3ff/(.*) [DOMAINNAME]/$1 [R=301,QSA,L] 
2
  • Actually, I have (.*) in my rules, for some reason asterisk doesn't display here. Commented Apr 8, 2011 at 20:56
  • 1
    Ok, I guess they get eaten up as italic marker by the parser. In that case your rules are correct and I could test them fine. Perhaps you are hitting a bug with this server. However keep in mind that as the first rule is marked as L (Last) you can never reach any of the other rules that would also fit a3ff/... Commented Apr 8, 2011 at 21:10