B6431
B6431

Reputation: 317

Mod Rewrite in htaccess is preventing the 301 Redirect from working properly

301 Redirects are not working properly because the ruleset in the mod rewrite is somehow getting added to the end of the 301 Redirect. For example, if my 301 Redirect looks like this:

Redirect 301 /directory/oldpage.html /directory/newpage.html

the redirect will go to:

/directory/newpage.html?section=directory&page=oldpage

Here is the mod rewrite in htaccess:

RewriteRule ^directory/(.*).html$  /directory/controller.php?section=directory&page=$1 [L]

page and section variables are defined through the included page’s file name.

Upvotes: 1

Views: 24

Answers (1)

anubhava
anubhava

Reputation: 784938

Have your rules in this order:

RewriteEngine On

RewriteRule ^directory/oldpage.html$ /directory/newpage.html [L,NC,R=301]

RewriteRule ^directory/([\w-]+)\.html$ directory/controller.php?section=directory&page=$1 [L,QSA,NC]

Make sure to test in a new browser to avoid old cache.

Upvotes: 1

Related Questions