Rejoanul Alam
Rejoanul Alam

Reputation: 5398

htaccess redirect not working in same domain

I want to redirect https://xxx.xxxx.com/zzz to https://xxx.xxxx.com/zzz247. I have tried this

Redirect 301 / https://xxx.xxxx.com/zzz247

So now when I try https://xxx.xxxx.com/zzz its take me into https://xxx.xxxx.com/zzz247zzz247zzz247zzz247zzz247zzz247zzz247....

How can I fix this issue? help please

What is required

I need enable only one URL which is https://xxx.xxxx.com/zzz247 even user type https://xxx.xxxx.com/zzz

Upvotes: 1

Views: 407

Answers (1)

anubhava
anubhava

Reputation: 786091

Instead of Redirect directive use RedirectMatch with regex support:

RedirectMatch 301 ^/zzz/?$ /zzz247

Redirect appends current URI into redirected URI and since you're matching / that will match anything and cause a redirect loop.

Make sure to clear your browser cache before testing.


Using RewriteRule you can do this:

RewriteRule ^zzz/?$ /zzz247? [L,NC,R=301]

? at the end of the target URI is for stripping any query string.

Upvotes: 3

Related Questions