更好的方式来编写这个 mod_rewrite 吗?

发布于 2024-12-23 14:17:19 字数 452 浏览 2 评论 0原文

我目前正在为我的所有页面使用这种类型的 mod_rewrite 代码......但我认为它太长了。一定有更短的方法来编写相同的代码吗?它会增加服务器上的任何负载吗?

RewriteRule ^Login/$ login.php [L]
RewriteRule ^login/$ login.php [L]
RewriteRule ^Login$ login.php [L]
RewriteRule ^login$ login.php [L]

第一行是普通网址 - “http://website/Login/”
第二个是如果用户没有输入大写“L” - “http://website/login/”
第三个是如果他没有在第一个网址上添加结束斜杠 - “http://website/Login”
第四个是如果他没有在第二个网址上添加结束斜杠 - “http://website/login”

I am currently using this type of mod_rewrite code for all my page...but i think its too long. There must be a shorter way of writing same code? and does it increase any kind of load on he server?

RewriteRule ^Login/$ login.php [L]
RewriteRule ^login/$ login.php [L]
RewriteRule ^Login$ login.php [L]
RewriteRule ^login$ login.php [L]

the first line is for normal url - "http://website/Login/"
second one is if the user doesn't type the capital "L" - "http://website/login/"
third one is if he doesn't add an ending slash on the first url - "http://website/Login"
fourth one is if he doesn't add an ending slash on the second url - "http://website/login"

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

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

发布评论

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

评论(4

拧巴小姐 2024-12-30 14:17:19

试试这个正则表达式:

^[Ll]ogin/?$

[Ll] 匹配 L 或 l,问号表示前面的字符(斜杠)是可选的。

Try this regex:

^[Ll]ogin/?$

[Ll] matches either L or l, question mark means the previous character (slash) is optional.

陌路黄昏 2024-12-30 14:17:19

除了@milan的回答之外,您还可以指定 NC 标志,这使得重写规则不区分大小写。

RewriteRule ^login/?$ login.php [NC,L]

参考

Further to @milan's answer, you could also specify the NC flag, of which makes the rewrite rule not case sensitive.

RewriteRule ^login/?$ login.php [NC,L]

Reference

心奴独伤 2024-12-30 14:17:19

例如:

RewriteRule ^[Ll]ogin/?$ login.php [L]

但我必须问,为什么?为什么不直接选择一个 URL 并坚持使用呢?您希望人们手动输入 URL 吗?

For example:

RewriteRule ^[Ll]ogin/?$ login.php [L]

But I must ask, why?? Why not simply choose one URL and stick with it? Do you expect people to enter the URL manually?

梦回梦里 2024-12-30 14:17:19
RewriteRule ^login/?$ login.php [L,NC]

应该做。 NC 表示不区分大小写,而 ?使斜杠可选。

RewriteRule ^login/?$ login.php [L,NC]

Should do it. NC is for case insensitivity and ? makes the slash optional.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文