Php Can';t访问网站';s根页面

Php Can';t访问网站';s根页面,php,.htaccess,web,Php,.htaccess,Web,通常,在我的网站上,qpcftw.cu.cc会透明地加载页面qpcftw.cu.cc/index.php,而不会在url中显示/index.php部分。我一直在尝试使用.htaccess摆脱.php扩展。这是my.htaccess文件的内容: <Files /> ForceType application/x-httpd-php </Files> RewriteEngine on RewriteBase / RewriteRule ^.htaccess$ - [F]

通常,在我的网站上,
qpcftw.cu.cc
会透明地加载页面
qpcftw.cu.cc/index.php
,而不会在url中显示
/index.php
部分。我一直在尝试使用.htaccess摆脱
.php
扩展。这是my.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

ForceType应用程序/x-httpd-php
重新启动发动机
重写基/
重写规则^.htaccess$-[F]
重写规则^([A-z,0-9,,-]+)?$$1.php[QSA]
重写规则^([A-z,0-9,,-]+)/index\.html$$1.php[QSA]
errordocument403php/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个标准:

  • qpcftw.cu.cc/index.php
    =
    qpcftw.cu.cc/index
  • 访问
    qpcftw.cu.cc/forum/
    仍会在
    qpcftw.cu.cc/forum/index.php加载我的PHPBB论坛
  • qpcftw.cu.cc
    透明地加载
    index.php
    文件,而不在URL中显示该文件

  • 到目前为止,我当前的.htaccess满足了前两个需求,但打破了第三个需求。救命啊/

    不要盲目地将.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的),但它不存在(我希望!),因此重写规则将失败


    我还从正则表达式类中删除了逗号(你不能用它们来表示多个组,放在那里只意味着URL中允许使用逗号),并在规则中添加了[L]ast标志以提高性能,如下所示。htaccess代码自动完成所有扩展隐藏魔法:

    Options +MultiViews
    

    很好,条件3现在满足了,但不幸的是,条件2坏了。也许这是我链接中的一个错误。我的链接应该指向
    /file.php
    还是仅仅指向
    /file
    ?对。第一条规则不适用于以/forum开头的URL。添加
    RewriteCond%{REQUEST\u URI}^/论坛
    到第一条重写规则(在
    RewriteCond$1.php-f
    之后,在新的一行)看来,
    /forum
    /forum
    的工作方式是一样的。哎呀,我的意思是它坏了#1,而不是2