无法访问网站的根页面

时间:2013-05-12 21:35:14

标签: php .htaccess web

通常,访问我的网站qpcftw.cu.cc会透明地加载页面qpcftw.cu.cc/index.php,而网址中不会显示/index.php部分。我一直试图使用.htaccess摆脱.php扩展。这是我的.htaccess文件的内容:

<Files />
ForceType application/x-httpd-php
</Files>

RewriteEngine on
RewriteBase /

RewriteRule ^.htaccess$ - [F]

RewriteRule ^([A-z,0-9,_,-]+)?$              $1.php     [QSA]
RewriteRule ^([A-z,0-9,_,-]+)/index\.html$    $1.php     [QSA]

ErrorDocument 403 php/error.php
ErrorDocument 404 /404.php
ErrorDocument 405 php/error.php
ErrorDocument 408 php/error.php
ErrorDocument 500 php/error.php
ErrorDocument 502 php/error.php
ErrorDocument 504 php/error.php

我需要满足3条标准:

  1. qpcftw.cu.cc/index.php == qpcftw.cu.cc/index
  2. 访问qpcftw.cu.cc/forum/仍会在qpcftw.cu.cc/forum/index.php
  3. 加载我的PHPBB论坛
  4. qpcftw.cu.cc透明地加载index.php文件,而不显示在网址
  5. 到目前为止,我目前的.htaccess满足了前2个需求,但打破了第3个。救命! :/

2 个答案:

答案 0 :(得分:1)

不要盲目地将.php添加到所有内容中,而是检查.php文件是否首先存在

RewriteCond $1.php -f 
RewriteRule ^([A-z0-9_-]+)?$              $1.php     [L,QSA]

RewriteCond $1.php -f
RewriteRule ^([A-z0-9_-]+)/index\.html$    $1.php     [L,QSA]

这仍然适用于1和2,现在3也可以工作,因为代码将测试index.php.php是否存在(请求是针对index.php),它不是(我希望!),所以RewriteRule会失败。

我还从正则表达式类中删除了逗号(你不能用它们来表示几个组,把它放在那里只是意味着URL中允许使用逗号),并在规则中添加了[L] ast标志为了更好的表现

答案 1 :(得分:1)

以下.htaccess代码会自动执行所有扩展隐藏魔法:

Options +MultiViews
相关问题