Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
修改my.htaccess文件以从URL隐藏.php扩展名后,无法找到某些目录项_Php_.htaccess - Fatal编程技术网

修改my.htaccess文件以从URL隐藏.php扩展名后,无法找到某些目录项

修改my.htaccess文件以从URL隐藏.php扩展名后,无法找到某些目录项,php,.htaccess,Php,.htaccess,最近,我在修改.htaccess文件以隐藏url中的.php扩展名时得到了一些帮助。在我让它工作后,我的网站出现了一些错误。无论出于何种原因,子目录中的任何php页面都会返回404错误。例如: mywebsite.com/test/test.php(这是404的) 但是 mywebsite.com/test/test.html(这很好用) 由于这只是在我的.htaccess文件被修改后才开始发生的,所以我假设问题就在那里。该文件包含以下内容: RewriteEngine On # Unless

最近,我在修改.htaccess文件以隐藏url中的.php扩展名时得到了一些帮助。在我让它工作后,我的网站出现了一些错误。无论出于何种原因,子目录中的任何php页面都会返回404错误。例如:

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

但是

mywebsite.com/test/test.html(这很好用)

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

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
如果有任何更多的信息,我可以提供帮助解决这个问题,请让我知道


感谢您的帮助。

在您的根目录中尝试以下规则。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]

如果您打算将PHP项目结构隐藏为目录树,以供public访问。。。您应该考虑在项目的根中添加一个.HTAccess文件,只需1行< /p> 将以下行添加到.htaccess文件中

Options -Indexes

那很有魅力!你的知识给我留下了深刻的印象,我很难理解。万分感谢,我真的很感谢你抽出时间来帮助我!最美好的祝愿你不受欢迎,很高兴它帮助了你。在.htaccess上是非常好的资源,以防您阅读。