![.htaccess 和斜杠的问题](https://linux22.com/image/187616/.htaccess%20%E5%92%8C%E6%96%9C%E6%9D%A0%E7%9A%84%E9%97%AE%E9%A2%98.png)
我正在尝试解决 .htaccess 的问题。
我的 .htaccess 中有这一行,但该网站仍然有“带斜杠”的版本。
抱歉,这是一个色情页面
https://carlamila.es/acompanantes-madrid.php/
提前致谢!!!
#With www to nonwww
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www.carlamila.es [NC]
RewriteRule (.*) https://carlamila.es/$1 [R=301,L,QSA]
</IfModule>
#Http to HTTPS
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule (.*) https://carlamila.es/$1 [R=301,L,QSA]
</IfModule>
#With to without slash
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*) http://carlamila.es/$1/ [R=301,L,QSA]
</IfModule>
答案1
现在效果很好:
<IfModule mod_rewrite.c>
RewriteEngine On
#Quitar el .php
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
#De http a https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#De www a sin www
RewriteCond %{HTTP_HOST} ^www.carlamila.es [NC]
RewriteRule ^(.*)$ http://carlamila.es/$1 [L,R=301]
#De barra a sin barra
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
ErrorDocument 404 /404.php
</IfModule>