问题描述
我想从重定向到
我在下面的代码中写了我的.htaccess:
I want to redirect from http://example.com/contact-us to http://example.com/contact-us/offices
I have written following line in my .htaccess:
重定向301 / contact-us /
Redirect 301 /contact-us/ http://example.com/contact-us/offices
但是当我访问,然后重定向到
But when I visit to http://example.com/contact-us then it redirects to http://example.com/contact-us/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/offices/
推荐答案
您正在使用以下规则:
Redirect 301 /contact-us/ http://example.com/contact-us/offices
这将重定向以 / contact-us /
开头的每个URL为 / contact-us的新URL / offices
。由于重定向URL也以 / contact-us /
开头,因此重定向将反复发生,从而导致重定向循环。为了避免这种情况,请使用具有正则表达式支持的 RedirectMatch
,以便您可以控制匹配模式。
That is redirecting every URL that starts with /contact-us/
new URL that is /contact-us/offices
. Since redirecting URL also starts with /contact-us/
therefore redirect will happen again and again causing a redirect loop. In order to avoid this situation use RedirectMatch
that has regex support so that you can control the matching pattern.
RedirectMatch 301 ^/contact-us/?$ http://example.com/contact-us/offices
在测试此更改之前,请不要忘记清除浏览器缓存。
Don't forget to clear your browser cache before testing this change.
这篇关于301通过.htaccess重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!