如何重定向单个段 url 末尾没有正斜杠?

How can I redirect a single segment url without forward slash at the end?

我网站的 htaccess 文件不允许单个段的末尾没有正斜杠的重定向。如果我离开它,它会循环并使网站崩溃。我怎样才能让我的用户去 [site].com/winter-camping 并让它被重定向?这是我目前有效的设置:

RewriteEngine On

RedirectMatch permanent /find-a-park/ https://[site].com/about/find-a-park
RedirectMatch permanent /winter-camping/ https://[site].com/about/promotion-details/winter-camping

#our rules:
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        # Removes index.php from ExpressionEngine URLs
        RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
        RewriteCond %{REQUEST_URI} !/system/.* [NC]
        RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]

        # Directs all EE web requests through the site index file
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/ [L]
</IfModule>

基本上我根本不希望我的用户在末尾添加正斜杠来访问该页面。

但是,我确实有一些实例可以正常工作,这就是我感到困惑的原因。唯一的区别是它们是子页面:

RedirectMatch permanent /parks/about/central-park https://[site].com/parks/central-park

需要知道的一件事是我们使用 ExpressionEngine 作为我们的 CMS。我怎样才能让前两个重定向来重定向他们的网址而不会使我的网站崩溃?谢谢

您应该只使用 mod_rewrite 规则并使用带有可选尾部斜杠的正则表达式:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^find-a-park/?$ https://[site].com/about/find-a-park [L,NC,R=301]
    RewriteRule ^winter-camping/?$ https://[site].com/about/promotion-details/winter-camping [L,NC,R=301]

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/ [L]
</IfModule>