: 301 redirect + RewriteRule not working together? 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
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 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 example.com/word1/word2
More posts by @Welton855
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.