当访客去时,说:
的http:// website.com/dir/dir2/file.html
我的重写会清除基本网址之外的路径,并使用www将其重定向到主页。在前面:
的http:// www.website.com/
如何防止剥离发生并将访问者发送到主页而不是他们请求的网址?仅供参考,有问题的URL存在。
感谢名单!
答案 0 :(得分:3)
在重写结束时包含文件/路径信息,如下所示:
RewriteCond %{HTTP_HOST} !^www\.website\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.website.com/$1 [L,R]
答案 1 :(得分:3)
仅供参考,这适用于Magento网站。
在.htaccess之后,
之后#RewriteBase /magento/
之后,我放置了他们自己的路线:
RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]
它有效。有孩子的爸爸也说得对,只是不知道第二行是什么。
答案 2 :(得分:1)
大多数人需要设置RewriteBase
,所以请尝试:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(?:www\.your-live-domain\.com|staging\.domain\.com)$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule .* http://www.your-live-domain.com/$0 [L,R=301]
使用301使其永久