在 WordPress 中使用 .htaccess 删除尾部斜杠 [英] Remove trailing slash using .htaccess in WordPress

查看:40
本文介绍了在 WordPress 中使用 .htaccess 删除尾部斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来删除所有 WordPress URL 的尾部斜杠.

I'm looking for a way to remove trailing slash for all WordPress URL's.

我找到了类似的答案,例如 这个 但是当之前有 WordPress .htaccess 规则时它不起作用.

I found similar answers like this one but it doesn't work when there's WordPress .htaccess rules before.

这是我当前的 WordPress .htaccess:

Here is my current WordPress .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

推荐答案

试试这个:

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]

    RewriteRule (.+)/$ $1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

如果它不起作用试试这个:

If it doesn't work try this one:

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]

    RewriteRule (.+)/$ http://www.domain.com/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

这篇关于在 WordPress 中使用 .htaccess 删除尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆