I am using a 301 redirect to redirect a page to another page in the same website, which uses RewriteRule to hide the PHP variables in a friendly URL.

My redirection code in .htaccess:

Redirect 301 /example/word1/word2/word3 http://www.example.com/word1/word2

As a result when I visit /word1/word2/word3 it redirects me to the URL set by a previous RewriteRule which is /word1/word2?var1=word1&var2=word2&var3=word3. Where var1, var2, and var3 are the PHP variables that have for content word1, word2 and word3.

I want the redirection to go just to www.example.com/word1/word2

1 Answer 1


You need to change your Redirect (mod_alias) to RewriteRule (mod_rewrite). Something like:

RewriteRule ^word1/word2/word3 /word1/word2 [R=301,L]

(Put back example/ if you wish, but it looked like a typo to me?)

The problem you are experiencing is that mod_rewrite (nearly) always executes before mod_alias, regardless of the order of directives in your .htaccess file. You should avoid mixing directives from both of these modules for this reason.

And as bybe suggests, make sure this comes before your other (internal) rewrites, as otherwise you could end up with the same problem. Generally, external redirects should always come before internal rewrites.

  • 1
    Beat me too it! ensure you set that above your other rewrites so it stops when word/word2/word3 is accessed. Apr 20, 2014 at 10:09
  • and what will happen with PageRank? I wanted to use 301 redirect so that it was not lost... Apr 20, 2014 at 10:11
  • 1
    This is still a 301 redirect (R=301), it's just a different way of doing it (using a different Apache module). But as bybe suggests, this should also come at the top of your .htaccess file (external redirects before internal rewrites).
    – MrWhite
    Apr 20, 2014 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.