省略尾部斜杠 (.htaccess) 后重定向不正确

发布于 2024-09-28 12:33:35 字数 1320 浏览 2 评论 0原文

我有以下 .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]

I have the following .htaccess file and I would like to know how can I edit it in order to add the trailing slash and keep the same url. Right now, if I access a link without a trailing slash, it adds the slash but it loses the 'www.' in front of 'mywebsite.com'. Any ideas?

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎言笑 2024-10-05 12:33:35

此规则将所有不带尾部斜杠的请求重定向到不带 www 的域:

RewriteRule ^(.*)$ http:// mywebsite.com/$1/ [L,R=301]

因此,如果您想添加 www,就在那里添加。

This rule is redirecting all requests without a trailing slash to your domain without www:

RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L,R=301]

So if you want to add www, add it right there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文