开发者

htaccess Redirect to Child Directory

开发者 https://www.devze.com 2023-03-21 23:47 出处:网络
I\'m trying to 301 redirect to a ch开发者_StackOverflow社区ild directory using .htaccess i.e. Redirect 301 /parent http://example.com/parent/child/

I'm trying to 301 redirect to a ch开发者_StackOverflow社区ild directory using .htaccess i.e.

Redirect 301 /parent http://example.com/parent/child/

Unfortunately this results in a redirect loop i.e.

/parent/child/child/child/child/etc.

Please could anyone point me in the right direction?


Redirect directive will match and redirect everything that starts with /parent. You need to use RedirectMatch to only redirect this specific folder:

RedirectMatch 301 ^/parent/?$ http://example.com/parent/child/

The same, but using mod_rewrite:

RewriteRule ^parent/?$ http://example.com/parent/child/ [R=301,L]

NOTES: Place it in .htaccess in website root folder. If placed elsewhere some small tweaking may be required.

0

精彩评论

暂无评论...
验证码 换一张
取 消