Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
.htaccess 从URL中删除index.php和后面的斜杠_.htaccess - Fatal编程技术网

.htaccess 从URL中删除index.php和后面的斜杠

.htaccess 从URL中删除index.php和后面的斜杠,.htaccess,.htaccess,在我的.htaccess中,我有以下重写规则,前4行应该处理允许在没有index.php的情况下访问站点的问题,并且工作正常,直到我添加最后一位,我尝试使用它从站点URL中删除尾部斜杠 RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond $1 !^(uploads|cache|themes|default|admin\.php|favicon\.ico|

在我的.htaccess中,我有以下重写规则,前4行应该处理允许在没有index.php的情况下访问站点的问题,并且工作正常,直到我添加最后一位,我尝试使用它从站点URL中删除尾部斜杠

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(uploads|cache|themes|default|admin\.php|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1

# Remove trailing slashes
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
当我添加最后一行,并访问我的站点的根目录时,index.php部分被附加到URL,这是为什么

当我添加最后一行,并访问我的站点的根目录时,index.php部分被附加到URL,这是为什么

这是因为规则是按顺序应用的。您希望在将内容路由到
/index.php
之前发生重定向。只需交换这些规则:

# Remove trailing slashes
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(uploads|cache|themes|default|admin\.php|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1  [L]

以下规则对我来说很有用

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

#Removing trailing slash
RewriteRule ^(.*)/$ /$1 [L,R]

#Removing index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=302,NE,L]