Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
1  
Beat me too it! ensure you set that above your other rewrites so it stops when word/word2/word3 is accessed. –  bybe Apr 20 at 10:09
    
and what will happen with PageRank? I wanted to use 301 redirect so that it was not lost... –  user2348684 Apr 20 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). –  w3d Apr 20 at 10:14
    
Great, it works! thank you! –  user2348684 Apr 20 at 10:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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