我的网站URL的末尾有一个斜杠,并显示为
https://mywebsite.com/
由于搜索引擎读取了
https://mywebsite.com/
and
https://mywebsite.com
作为两个不同的URL,我要删除它们。
这是我现有的.htaccess文件
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<ifModule mod_headers.c>
<filesMatch "\\.(css|js|html|jpg|png)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
</ifModule>
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$
RewriteRule ^/?$ "https\:\/\/mywebsite\.com\/" [R=301,L]
要在末尾删除斜杠,我必须添加以下代码:
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $ 1 [L,R =301]
我的网站有HTTPS。每当添加以上代码时,我最终都会出错。如何添加它而不弄乱现有配置。