Php 停止htaccess检测文件夹本身,而是使用重写规则
如何停止.htaccess检测文件夹本身,而改用重写规则 我找到的东西都试过了 这是我当前的.htaccess:Php 停止htaccess检测文件夹本身,而是使用重写规则,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,如何停止.htaccess检测文件夹本身,而改用重写规则 我找到的东西都试过了 这是我当前的.htaccess: Options -Indexes +FollowSymlinks DirectorySlash Off RewriteEngine On #Block direct access to root php files RewriteRule ^(init|404|_header|_footer|home)\.php$ index.php?error [L] #Get doc R
Options -Indexes +FollowSymlinks
DirectorySlash Off
RewriteEngine On
#Block direct access to root php files
RewriteRule ^(init|404|_header|_footer|home)\.php$ index.php?error [L]
#Get doc
RewriteRule ^docs/([^/]+)/?$ index.php?doc=$1 [L]
#Get release
RewriteRule ^releases/([^/]+)/?$ index.php?release=$1 [L]
#Get page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/]+)/?$ index.php?page=$1 [L]
DirectoryIndex index.php
Options -Indexes +FollowSymlinks
DirectorySlash On
RewriteEngine On
#Block direct access to root php files
RewriteRule ^(init|404|_header|_footer|home)\.php$ index.php?error [L]
RewriteRule ^$ index.php [L]
#Get doc
RewriteRule ^docs/(.*)$ index.php?doc=$1 [L]
#Get release
RewriteRule ^releases/(.*)$ index.php?release=$1 [L]
#Get page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/]+)/?$ index.php?page=$1 [L,QSA]
注意事项:
- 我在服务器中有文件夹
,文档
和发行版
页面
- 我想给所有PHP文件提供404错误,但在根目录上没有index.PHP
(不带尾随斜杠)抛出403错误,这也是因为site.com
,但是如果我删除它,它会显示文件夹而不是加载默认页面选项-索引
- 如果我删除
,它解决了前面的问题,但当我转到与文件夹匹配的链接时,它会忽略重写规则,然后附加查询字符串(例如目录slash Off
)。当然,它显示了我想要的正确页面,但仍然是,那个链接让我很烦site.com/docs/?page=docs
拒绝
,即使排除了CSS、JS和图像,但我得到了意想不到的结果。我想为所有PHP文件提供404错误,但在根目录下的index.PHP除外。您的完整.htaccess:
Options -Indexes +FollowSymlinks
DirectorySlash Off
RewriteEngine On
#Block direct access to root php files
RewriteRule ^(init|404|_header|_footer|home)\.php$ index.php?error [L]
#Get doc
RewriteRule ^docs/([^/]+)/?$ index.php?doc=$1 [L]
#Get release
RewriteRule ^releases/([^/]+)/?$ index.php?release=$1 [L]
#Get page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/]+)/?$ index.php?page=$1 [L]
DirectoryIndex index.php
Options -Indexes +FollowSymlinks
DirectorySlash On
RewriteEngine On
#Block direct access to root php files
RewriteRule ^(init|404|_header|_footer|home)\.php$ index.php?error [L]
RewriteRule ^$ index.php [L]
#Get doc
RewriteRule ^docs/(.*)$ index.php?doc=$1 [L]
#Get release
RewriteRule ^releases/(.*)$ index.php?release=$1 [L]
#Get page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/]+)/?$ index.php?page=$1 [L,QSA]
还是不能解决我的第一个问题。我在
site.com
上仍然收到403个错误,后面没有斜杠。仍然没有,抱歉。它解决了第一个问题,但随后在site.com/docs
、site.com/releases
和site.com/pages
上给出了403,也就是说,在这些链接的所有子页面上给出了404,第二个和第三个重写规则不再有效。site.com/pages
是否被重定向到site.com/pages/
,因为我现在有了directorysslash
?是的,但是我想选项-索引
比重写规则优先,并且仍然阻止对页面的访问。这次,文件夹获取404错误。我想重写规则不是问题,而是其他所有问题。你怎么认为?顺便说一句,我还得到了文件夹链接的尾随斜杠,但如果是site.com/something
,则不会。我猜解决方案是删除DirectorySlash,但也会破坏主页,对吗?