Htacess重写规则 - 不无尾随斜线工作 [英] Htacess Rewrite Rule - Doesn't work without Trailing Slash

查看:266
本文介绍了Htacess重写规则 - 不无尾随斜线工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有以下重写规则:

So I have the following Rewrite Rules:

RewriteRule ^([a-z0-9_\-]+)(\.php)?$ index.php?page=$1 [NC,L,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?shop=$1&page=index [NC,L,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z_-]+).php$ index.php?shop=$1&page=$2 [NC,L,QSA]

一切似乎都工作很好,如果我去domain.com/shop/~~V那么它工作正常,并给出了指数。如果我去domain.com/shop/about.php~~V那么它完美的作品。

Everything seems to work great, if I go to domain.com/shop/ then it works fine and shows the index. If I go to domain.com/shop/about.php then it works perfect.

这是行不通的唯一的事情是,当我去没有斜线来domain.com/shop~~V,它不显示任何内容,我收到了一堆错误。

The only thing that does not work is when I go to domain.com/shop without a trailing slash, it does not display anything I get a bunch of errors.

有谁知道如何解决这一问题?这可能是一些超级简单添加到我的code,但我似乎无法找到答案。

Does anyone know how to fix this? It's probably something super simple to add to my code but I can't seem to figure it out.

谢谢!

推荐答案

在你的第二个规则,添加 斜线后:

In your second rule, add ? after trailing slash:

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?shop=$1&page=index [NC,L,QSA]

这会使尾 /

这篇关于Htacess重写规则 - 不无尾随斜线工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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