Mobile app version of vmapp.org
Login or Join
Welton855

: 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

@Welton855

Posted in: #Htaccess #ModRewrite #Php #Redirects #UrlRewriting

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Welton855

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme