使用www和斜杠进行htaccess重定向的奇怪行为

时间:2018-01-08 12:02:51

标签: html .htaccess

我对网站进行了分析,并遇到了htaccess重定向问题。这很奇怪,我之前做了很多次,从来没有像这样的问题。 因此,我尝试将我的domen重定向到没有www和shash:

 ErrorDocument 404 /404.html
RewriteEngine On
    RewriteBase /

    rewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://domen.com/$1 [R=301,L]

我还删除了url末尾的斜杠

 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)/$ /$1 [L,R=301]

然后我从不存在或未使用的页面重定向到404错误:

RedirectMatch 404 ^/non-existing-page$ or ^/non-existing-page/$

当我在浏览器http://www.domen.com/non-existing-page(使用www)或http:domen.com/non-existing-page(使用斜杠)中输入时,a具有相同的网址,包含404错误代码和404 html代码。没关系。

但如果我写了网址http://www.domen.com/non-existing-pag/(使用www和shash),我会被重定向到404.html页面,其中包含200 - 无错误代码。

出了什么问题?

在.htaccess开始时我只有

<IfModule mod_speling.c>
CheckSpelling on
</IfModule>

这就是全部。

0 个答案:

没有答案