简体   繁体   中英

htaccess rewriting double // after remving index.php

I have an url like this

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

and after removing index.php I have this

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

As you see I have // . How to remove one ?

thank you.

<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>

It is due to your remove index.php rule that is adding one extra / to make it // . Change that rule to:

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

And make sure to clear your browser cache before testing this change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM