首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何重定向htaccess中除某些文件夹之外的所有通信量?

问如何重定向htaccess中除某些文件夹之外的所有通信量?
EN

Stack Overflow用户
提问于 2015-07-28 06:17:33
回答 1查看 30关注 0票数 1

我一直在扯我的头发。我想重定向所有的流量到我的新网站。

为了论证起见,新的站点是mysite.org。然而,有某些网页和规则和文件夹,我想重定向到新的网站-如果用户不访问这些文件夹或规则-它应该是一个通用的重定向到我的网站?

代码语言:javascript
复制
redirect 301 / http://example.org
redirect 301 /index.php http://example.org
redirect 301 /index.html http://example.org
redirect 301 /contact.php http://example.org/contact-us
redirect 301 /store-locator/list.php http://example.org/store-locator
redirect 301 /store-locator/ http://example.org/store-locator
redirect 301 /about.php http://example.org/about-us
redirect 301 /customer-care.php http://example.org/contact-us
redirect 301 /hq-location.php http://example.org/store-locator
redirect 301 /privacy.php http://example.org/privacy
redirect 301 /terms.php http://example.org/terms
redirect 301 /policy.php http://example.org/returns
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-28 06:21:26

您最好使用RedirectMatch而不是Redirect,因为RedirectMatch使用regex并且只匹配匹配的URI,而Redirect匹配任何以提供的模式开始的URI,因此您的第一个规则将始终执行,使得所有后续规则都无效。

代码语言:javascript
复制
RedirectMatch 301 ^/$ http://example.org
RedirectMatch 301 ^/index\.(html|php)$ http://example.org
RedirectMatch 301 ^/contact\.php$ http://example.org/contact-us
RedirectMatch 301 ^/store-locator/list\.php$ http://example.org/store-locator
RedirectMatch 301 ^/store-locator/?$ http://example.org/store-locator
RedirectMatch 301 ^/about\.php$ http://example.org/about-us
RedirectMatch 301 ^/customer-care\.php$ http://example.org/contact-us
RedirectMatch 301 ^/hq-location\.php$ http://example.org/store-locator
RedirectMatch 301 ^/privacy\.php$ http://example.org/privacy
RedirectMatch 301 ^/terms\.php$ http://example.org/terms
RedirectMatch 301 ^/policy\.php$ http://example.org/returns

请确保在清除浏览器缓存后对其进行测试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31668669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档