.htaccess htaccess在删除index.php后重写double //

kh212irz  于 2022-11-25  发布在  PHP
关注(0)|答案(1)|浏览(108)

我有一个这样的网址

https://example.com /index.php/Products/Description/nikon-d300/Id-9

在删除index.php之后,我得到了这个

https://example.com //Products/Description/nikon-d300/Id-9

如您所见,我有//。如何删除一个?
谢谢你,谢谢你。

<IfModule mod_rewrite.c>
RewriteEngine On
DirectorySlash Off

# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=302,L]

# Remove Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^ %1 [R=302,L]

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

# Reroute to index.php
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?cURL=/$1 [L,QSA]
</IfModule>
xam8gpfp

xam8gpfp1#

这是因为您的remove index.php规则会额外增加一个/,使其成为//。请将该规则变更为:

# remove index.php
RewriteCond %{THE_REQUEST} /index\.php[\s?/] [NC]
RewriteCond %{REQUEST_URI} ^(.*/)?index\.php(?:/(.*))?/?$ [NC]
RewriteRule ^ %1%2 [L,R=301,NE]

并确保在测试此更改之前清除浏览器缓存。

相关问题