我有许多需要重定向到新位置的 URL,但在某些情况下,子页面需要保持事件状态而不是重定向。例如:/products
将重定向到 http://www.newsite.com/products
/products/category1
将重定向到 http://www.newsite/products/category1
但是 /products/specialitem
根本不会被重定向。
这可以通过 Redirect 或 RedirectMatch 实现吗?
做一个 Redirect 301 /products http://www.newsite.com/products
似乎影响所有子页面
感谢您的任何指导!
编辑:
使用 waynethec 的回答,我就可以开始了。但是谁能澄清为什么我下面的第一条规则有效而其他规则无效?RedirectMatch 301 ^segment-one$ http://www.google.com/
RedirectMatch 301 ^segment-one/segment-two$ http://news.google.com/
RedirectMatch 301 ^segment-one/segment-two/segment-three$ http://cnn.com/
RedirectMatch 301 ^segment-one/segment-two/segment-three/foobar$ http://gbv.com/
(不工作,我的意思是我仍然可以访问页面,而不是它们被重定向。)
最佳答案
您应该能够使用以下 RedirectMatch 规则:
RedirectMatch 301 ^/products$ http://www.newsite.com/products
请注意,这只会重定向对/products 的请求,而不是/products/或/products/pagename.extension。
关于apache - .htaccess 为父级而不是子级重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26320606/