开发者

mod-rewrite redirect parent URL to sibling URL

开发者 https://www.devze.com 2023-01-17 02:46 出处:网络
I\'ve read over the s开发者_运维百科imilar questions on stackoverflow, but have been unable to get this working. I keep getting stuck in an infinite loop.

I've read over the s开发者_运维百科imilar questions on stackoverflow, but have been unable to get this working. I keep getting stuck in an infinite loop.

I'm trying to redirect a specific url to a child of that url. eg:

Redirect 301 /category/parent-cat http://domain.com/category/parent_cat/child_cat


Sticking with mod_alias, you could use RedirectMatch instead so that you could anchor the pattern at the end of the URL:

RedirectMatch 301 ^/([^/]+/[^/]+)/?$ http://example.com/$1/child_cat

The mod_rewrite solution is almost identical:

RewriteEngine on

RewriteCond ^([^/]+/[^/]+)/?$ http://example.com/$1/child_cat [R=301,L]

You could naturally replace the [^/]+ patterns with the specific paths you were looking for, as well. I thought I'd provide a more general solution just in case, though.

0

精彩评论

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