使用 .htaccess 删除尾部斜杠

发布于 01-01 12:22 字数 606 浏览 5 评论 0原文

我正在尝试使用此模式从网址中删除斜杠

http://localhost/~francesco/mycms/ about/

使其

http://localhost/~francesco/mycms/about

我尝试了很多规则但没有一个正在为我工​​作。

我的重写规则现在是这样

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~francesco/mycms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?page=$1 [L]
</IfModule>

希望有人可以帮助我!

I am trying yo remove the trail slash from an url with this pattern

http://localhost/~francesco/mycms/about/

to make it

http://localhost/~francesco/mycms/about

I have tried lots of rules but no one is working for me.

My rewrite rule is this by now

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~francesco/mycms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?page=$1 [L]
</IfModule>

Hope someone can help me!

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

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

发布评论

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

评论(1

沉默的熊2025-01-08 12:23:00

规则放在

RewriteRule ^(about)/$ $1 [L,R=301,NC]

尝试将此

RewriteBase /~francesco/mycms/

如果您想在 RewriteBase 之后的任何一级目录中工作,即 http://localhost/~francesco/mycms/[anything-here]/ 使用

#exclude the /~francesco/mycms/admin/directory
RewriteCond %{REQUEST_URI} !^/admin/ [NC] 
RewriteRule ^([^/]+)/$ $1 [L,R=301,NC]

Try placing this rule

RewriteRule ^(about)/$ $1 [L,R=301,NC]

just after

RewriteBase /~francesco/mycms/

If you want to work for any first level directory following the RewriteBase i.e. http://localhost/~francesco/mycms/[anything-here]/ use

#exclude the /~francesco/mycms/admin/directory
RewriteCond %{REQUEST_URI} !^/admin/ [NC] 
RewriteRule ^([^/]+)/$ $1 [L,R=301,NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文