首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重写index.php后的htaccess重写双//

重写index.php后的htaccess重写双//
EN

Stack Overflow用户
提问于 2022-07-10 16:10:52
回答 1查看 26关注 0票数 1

我有一个像这样的网址

代码语言:javascript
复制
https://example.com /index.php/Products/Description/nikon-d300/Id-9

在移除index.php之后我有了这个

代码语言:javascript
复制
https://example.com //Products/Description/nikon-d300/Id-9

如你所见,我有//。如何移除一个?

谢谢。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-10 17:16:35

正是由于您的remove index.php规则,添加了一个额外的/来使其成为//。将该规则改为:

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72929965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档