修改我的.htaccess文件来隐藏PHP扩展的URL后,有些目录项目是无法被发现 [英] After modifying my .htaccess file to hide the .php extension from the URL, some directory items are unable to be found

查看:149
本文介绍了修改我的.htaccess文件来隐藏PHP扩展的URL后,有些目录项目是无法被发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我得到了一些帮助修改我的.htaccess文件来隐藏PHP扩展的URL。当我得到它的工作,一些错误发生与我的网站。无论出于何种原因,在子目录中的任何PHP页面返回404错误。例如:

Recently, I got some help modifying my .htaccess file to hide the .php extension in the url. After I got it working, a few bugs occurred with my site. For whatever reason, any php page in a sub directory returns a 404 error. For example:

mywebsite.com/test/test.php(这个404的)

mywebsite.com/test/test.php (this 404's)

mywebsite.com/test/test.html(这工作就好了)

mywebsite.com/test/test.html (this works just fine)

由于这只是开始发生我的.htaccess文件被修改后,我假设问题在于那里。该文件包含如下:

Since this only started occurring after my .htaccess file was modified, I am assuming the problem lies there. The file contains as follows:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.mywebsite.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /.+?\.php [NC]
RewriteRule ^(.+?)\.php$ /$1 [R=301,L,NE]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

ErrorDocument 404 /404.php

DirectoryIndex index.php

如果有任何更多的信息,我可以提供,以帮助解决这个问题,请让我知道!

If there is any more information I can provide to help solve this, please let me know!

感谢您的所有帮助。

推荐答案

在你的根目录的.htaccess尝试这些规则:

Try these rules in your root .htaccess:

ErrorDocument 404 /404.php    
DirectoryIndex index.php
RewriteEngine On
RewriteBase /

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ /$1 [R=301,L,NE]

# Redirect external .php requests to extensionless url
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /.+?\.php [NC]
RewriteRule ^(.+?)\.php$ /$1 [R=301,L,NE]

# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

这篇关于修改我的.htaccess文件来隐藏PHP扩展的URL后,有些目录项目是无法被发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆