Reputation: 612
I have a redirect rule on htaccess that simply points a parent page to its child page.
Redirect 301 /swu-members-only/ /swu-members-only/home/
However, when I try to access the page i'm trying to redirect, it returns a URL like this: http://simonwu.com.au/swu-members-only/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home
What causes the redirect loop like this to happen? Any suggestions to fix is greatly appreciated.
Upvotes: 0
Views: 29
Reputation: 42885
The reason for the redirection loop is that the pattern you rewrite also matches your target path. So when the client sends the next request to the specified target it again gets redirected...
You can get around that by forcing an exact match:
RedirectMatch "^/swu-members-only/?$" "/swu-members-only/home/"
Another option is to use the rewriting module which offers much more flexibility:
RewriteEngine on
RewriteRule "^/?swu-members-only/?$" "/swu-members-only/home/" [R=302]
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug, they really slow down the http server, often for nothing and they can open pathways to security nightmares. They are only provided for situations where you do not have access to the real http servers host configuration (read: really cheap service providers).
Upvotes: 1