.htaccess错误“遇到404找不到错误”

时间:2015-03-04 08:10:55

标签: php .htaccess

我已在.htaccess文件中设置代码,如下所示

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^mydomain.in$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.in/$1 [R=301,L]
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

主页打开很好,但其他页面显示错误:

在此服务器上找不到请求的网址/目录/产品。 此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。

提前感谢

1 个答案:

答案 0 :(得分:1)

你的规则全都乱了。试试这个:

RewriteEngine On

# Redirect non-www to www
RewriteCond %{HTTP_HOST} ^mydomain.in$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.in/$1 [R=301,L]

# Do not redirect existing files/dirs
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# Redirect everything else to index.php
RewriteRule ^.*$ index.php [NC,L]