【问题标题】:Incorrect redirection after omitting a trailing slash (.htaccess)省略尾部斜杠 (.htaccess) 后重定向不正确
【发布时间】:2010-10-21 20:48:13
【问题描述】:

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

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

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

    RewriteRule ^(.*)$ @987654321@$1/ [L,R=301]

    所以如果你想添加 www,就在此处添加。

    【讨论】:

    • 好的,如果我想将所有不带www的请求重定向到带www的url?
    • 这是一个单独的问题,不属于现有问题的 cmets。此外,还有数十篇文章告诉您使用两行规则来完成快速搜索。
    猜你喜欢
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多