Reputation: 254
I have a redirect like this
Redirect 301 /dir/dir/843-987 /new_page
but instead to redirect to "/new_page" it does "/new_page/843-987" Why? And how to avoid this?
Upvotes: 1
Views: 133
Reputation: 5712
If 843-987
is a static term, you can use the following code:
RewriteRule ^dir/dir/843-987/?$ /new_page [L,NC,R=301]
If 843-987
is a range of number, you can use the following code:
RewriteRule ^dir/dir/(84[3-9]|8[5-9][0-9]|9[0-7][0-9]|98[0-7])/?$ /new_page [L,NC,R=301]
Breaking down for 843
to 987
range:
Parse Into Range:
843 - 849
850 - 899
900 - 979
980 - 987
Parse Into Block Regex:
84[3-9]
8[5-9][0-9]
9[0-7][0-9]
98[0-7]
Combining Into Regex Pattern:
(84[3-9]|8[5-9][0-9]|9[0-7][0-9]|98[0-7])
Upvotes: 1
Reputation: 785146
That is how Redirect
directive works as it appends current URI to target.
You should use more power mod_rewrite
rules for finer control:
RewriteEngine On
RewriteRule ^dir/dir/843-987/?$ /new_page [L,NC,R=301]
Make sure to use a new browser to test the change or clear cache completely.
Upvotes: 1