我有以下.htaccess文件,我想知道如何编辑它以添加尾部斜杠并保持相同的URL。现在,如果我访问没有尾部斜杠的链接,它会添加斜杠,但它会丢失“www”。在'mywebsite.com'面前。有任何想法吗?
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*).html
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L,R=301]
RewriteRule ^artists/([^/-]+)-p([^/]+)/$ /artists.php?l=$1&p=$2 [QSA,L]
RewriteRule ^artists/([^/]+)/$ /artists.php?l=$1 [QSA,L]
RewriteRule ^lyrics/(.*)/(.*)/(.*).html /artists-lyrics.php?a=$1&b=$2&c=$3
RewriteRule ^lyrics/(.*)/(.*).html /artists-lyrics.php?a=$1&c=$2 [QSA,L]
RewriteRule ^lyrics/([^/]+)/([^/]+)/$ /artists-albums.php?a=$1&b=$2 [QSA,L]
RewriteRule ^lyrics/([^/]+)/$ /artists-details.php?a=$1 [QSA,L]
RewriteRule ^latest/p-([^/-]+)-([^/]+)/$ /latest.php?p=$1&q=$2 [QSA,L]
RewriteRule ^save-([^/-]+)-([^/-]+)/$ /save.php?t=$1&s=$2 [QSA,L]
RewriteRule ^latest/$ /latest.php [QSA,L]
RewriteRule ^top100/$ /top100.php [QSA,L]
RewriteRule ^p-([^/-]+)-([^/]+)/$ /index.php?p=$1&q=$2 [QSA,L]
RewriteRule ^submit/$ /submit.php [QSA,L]
RewriteRule ^users/$ /users.php [QSA,L]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mywebsite.com/$1 [R=301,L]
答案 0 :(得分:1)
此规则会在没有www:
的情况下将没有尾部斜杠的所有请求重定向到您的域 RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L,R=301]
因此,如果您想添加www,请将其添加到那里。