URL rewrite not working for one URL

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteRule ^foo$ /bar [L,R=301]

</IfModule>

# END WordPress

Those lines are working for wordpress but RewriteRule ^foo$ /bar [L,R=301] is not redirecting when I open www.example.com/foo

Related posts

Leave a Reply

2 comments

  1. Order of RewriteRule matters in .htaccess. Change your .htaccess code to this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^foo/?$ /bar [L,R=301]
    
    RewriteRule ^index.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    </IfModule>
    # END WordPress
    
  2. Have you tried putting that specific rule just below the RewriteBase / rule? I think the other rules are already doing stuff causing your last one to be ignored.