【问题标题】:Removing trailing slash in the home page url删除主页 url 中的尾部斜杠
【发布时间】:2014-03-07 09:24:14
【问题描述】:

我遵循了这个:Mode Rewrite; with/without trailing slash on end of url? 解决方案,但它不适用于我的 mybb 网站。我试过将它添加到 .htaccess 的顶部和底部......但没有用。 我可能会错过什么?

这是我的 .htaccess,我已将 mysite 替换为 example.com:

Options -MultiViews +FollowSymlinks -Indexes
<IfModule mod_security.c>
    # Turn off mod_security filtering.
    SecFilterEngine Off
    # The below probably isn't needed, but better safe than sorry.
    SecFilterScanPOST Off
</IfModule>


<IfModule mod_rewrite.c>
    RewriteEngine on

RedirectMatch 301 ^/archive/index\.php/?(.*)  /$1
    # Some hosts need a RewriteBase specification.
    RewriteBase /
    # Google SEO workaround for search.php highlights:
    # Make this rule the first rewrite rule in your .htaccess!
    RewriteRule ^([^&]*)&(.*)$ http://forum.example.com/$1?$2 [L,QSA,R=301]
    # Google SEO Sitemap:
    RewriteRule ^sitemap-([^./]+)\.xml$ misc.php?google_seo_sitemap=$1 [L,QSA,NC]
    # Google SEO URL Forums:
    RewriteRule ^Forum-([^./]+)$ forumdisplay.php?google_seo_forum=$1 [L,QSA,NC]
    # Google SEO URL Threads:
    RewriteRule ^Thread-([^./]+)$ showthread.php?google_seo_thread=$1 [L,QSA,NC]
    # Google SEO URL Announcements:
    RewriteRule ^Announcement-([^./]+)$ announcements.php?google_seo_announcement=$1 [L,QSA,NC]
    # Google SEO URL Users:
    RewriteRule ^User-([^./]+)$ member.php?action=profile&google_seo_user=$1 [L,QSA,NC]
    # Google SEO URL Calendars:
    RewriteRule ^Calendar-([^./]+)$ calendar.php?google_seo_calendar=$1 [L,QSA,NC]
    # Google SEO URL Events:
    RewriteRule ^Event-([^./]+)$ calendar.php?action=event&google_seo_event=$1 [L,QSA,NC]
    # Google SEO 404:
    ErrorDocument 404 /misc.php?google_seo_error=404
    # Default MyBB Rewrite Rules:
    RewriteRule ^forum-([0-9]+)\.html$ forumdisplay.php?fid=$1 [L,QSA]
    RewriteRule ^forum-([0-9]+)-page-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2 [L,QSA]
    RewriteRule ^thread-([0-9]+)\.html$ showthread.php?tid=$1 [L,QSA]
    RewriteRule ^thread-([0-9]+)-page-([0-9]+)\.html$ showthread.php?tid=$1&page=$2 [L,QSA]
    RewriteRule ^thread-([0-9]+)-lastpost\.html$ showthread.php?tid=$1&action=lastpost [L,QSA]
    RewriteRule ^thread-([0-9]+)-nextnewest\.html$ showthread.php?tid=$1&action=nextnewest [L,QSA]
    RewriteRule ^thread-([0-9]+)-nextoldest\.html$ showthread.php?tid=$1&action=nextoldest [L,QSA]
    RewriteRule ^thread-([0-9]+)-newpost\.html$ showthread.php?tid=$1&action=newpost [L,QSA]
    RewriteRule ^thread-([0-9]+)-post-([0-9]+)\.html$ showthread.php?tid=$1&pid=$2 [L,QSA]
    RewriteRule ^post-([0-9]+)\.html$ showthread.php?pid=$1 [L,QSA]
    RewriteRule ^announcement-([0-9]+)\.html$ announcements.php?aid=$1 [L,QSA]
    RewriteRule ^user-([0-9]+)\.html$ member.php?action=profile&uid=$1 [L,QSA]
    RewriteRule ^calendar-([0-9]+)\.html$ calendar.php?calendar=$1 [L,QSA]
    RewriteRule ^calendar-([0-9]+)-year-([0-9]+)\.html$ calendar.php?action=yearview&calendar=$1&year=$2 [L,QSA]
    RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ calendar.php?calendar=$1&year=$2&month=$3 [L,QSA]
    RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4 [L,QSA]
    RewriteRule ^calendar-([0-9]+)-week-(n?[0-9]+)\.html$ calendar.php?action=weekview&calendar=$1&week=$2 [L,QSA]
    RewriteRule ^event-([0-9]+)\.html$ calendar.php?action=event&eid=$1 [L,QSA]
    <IfModule mod_env.c>
        SetEnv SEO_SUPPORT 1
    </IfModule>
    #Added by Anurag
    RewriteRule ^index\.php(.*)$ http://%{HTTP_HOST}$1 [L,R=301]

</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>


AddType text/javascript .js

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 5 seconds"
    ExpiresByType image/x-icon "access plus 800000 seconds"
    ExpiresByType image/jpeg "access plus 800000 seconds"
    ExpiresByType image/png "access plus 800000 seconds"
    ExpiresByType image/gif "access plus 800000 seconds"
    ExpiresByType application/x-shockwave-flash "access plus 800000 seconds"
    ExpiresByType text/css "access plus 800000 seconds"
    ExpiresByType text/javascript "access plus 800000 seconds"
    ExpiresByType application/x-javascript "access plus 800000 seconds"
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\\.(ico|jpe?g|png|gif|swf|css|js)$">
        Header set Cache-Control "max-age=800000, public"
    </FilesMatch>
    Header unset ETag
    Header unset Last-Modified
</IfModule>
RewriteRule ^(.*)/$ /$1 [L,R=301]

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    尝试在RewriteBase / 行下方添加此规则:

    # remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{THE_REQUEST} \s.+?/+[?\s]
    RewriteRule ^(.+?)/$ /$1 [R=301,L,NE]
    

    【讨论】:

    • 它不工作。我什至在评论第二个条件后尝试过。
    • 这是经过全面测试的规则。对于哪个 URL 不起作用?
    • 对于 http://forum.example.com/ 我在 http 后面放了一个空格
    • 该 URL 中没有尾部斜杠。尾部斜线类似于forum.example.com/forum/
    • 你是对的:这是答案:stackoverflow.com/questions/11355328/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    • 2018-10-19
    • 2016-01-10
    • 1970-01-01
    • 2014-06-19
    相关资源
    最近更新 更多