apache - .htaccess 为父级而不是子级重定向?

标签 apache .htaccess mod-rewrite redirect

我有许多需要重定向到新位置的 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/

相关文章:

ruby-on-rails - 如何在 linux apache 托管服务器(即主机、bluehost)中使用 https 配置 redmine

php - WordPress 不支持 .htaccess

regex - 301 将 pdf 文件重定向到我的新网站

php - .htaccess 内部重定向不适用于字符串参数

regex - 如何使 mod_rewrite 从子域重定向到查询字符串?

apache - 特定子域上的 TLS 相互身份验证

java - Eclipse错误:Target runtime jre1. 8.0_31未定义

java - 注入(inject)器作业后 Nutch 2.2.1 不继续

php - 上传表单 - 无法上传/发布超过 120 Kb

apache - Mod_rewrite + 主题标签