htaccess伪静态不生效报错解决方法

2015年8月19日17:27:42 1 6,973 ℃

今天遇到一个网站报错“抱歉~~~服务器运行脚本错误”,如下图:

htaccess伪静态不生效报错解决方法

一开始认为是环境问题,重新加载环境以后故障依旧,然后开始排查伪静态文件,把.htaccess重命名以后的确可以访问,但是网站内页404错误。于是开始检查伪静态规则,规则如下:

RewriteEngine on
RewriteBase /
DirectoryIndex web/index.php
RewriteRule haoshentuochangjia/$ web/company.php?id=1
RewriteRule haoshentuochanpin/$ web/products.php?id=2
RewriteRule xinkuanhaoshentuo/$ web/products.php?id=3
RewriteRule haoshentuotuobazixun/$ web/news.php?id=4
RewriteRule haoshentuoshipin/$ web/company.php?id=2
RewriteRule sitemap.html/ web/sitemap.php
RewriteRule ([a-z]+).html$ web/$1.php

由于此网站结构较复杂,和我们一般的网站都不同,他网站程序是放在的根目录的二级目录里,然后通过伪静态指定首页文件路径跳转访问。

删除首页跳转规则(DirectoryIndex web/index.php)以后域名+目录可以访问,但是直接访问域名无法跳转,由于服务器还有一个网站和这个网站使用的同样的程序访问正常,所以排除了服务器原因。于是去查看了网站的报错日志,分析怀疑是网站的配置文件伪静态配置有问题,把两个配置文件下载到本地的确发现第11行不同(相同的代码我省略了未贴出),把AllowOverride AuthConfig FileInfo更改为AllowOverride All更改以后测试访问正常,下图:

<VirtualHost *:80>
        ……
        AddHandler php5-cgi .php
        Action php5-cgi /php5-cgi
        AllowOverride AuthConfig FileInfo //此处不同
        Options -Indexes -ExecCGI Includes IncludesNOEXEC FollowSymLinks
        Allow from all
    </Directory>
        ……
</VirtualHost>
<VirtualHost *:80>
        ……
        AddHandler php5-cgi .php
        Action php5-cgi /php5-cgi
        AllowOverride All //正常
        Options -Indexes -ExecCGI Includes IncludesNOEXEC FollowSymLinks
        Allow from all
    </Directory>
        ……
</VirtualHost>

百度搜索得出结论:在 AllowOverride 设置为 None 时, .htaccess 文件将被完全忽略。当此指令设置为 All 时,所有具有 ".htaccess" 作用域的指令都允许出现在 .htaccess 文件中,大多数情况下用AllowOverride All即可。

htaccess伪静态不生效报错解决方法

【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:1   其中:访客  0   博主  0

    • avatar 一尾流莺 6

      同意博主的观点,赞一个!