更好的方式来编写这个 mod_rewrite 吗?
我目前正在为我的所有页面使用这种类型的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个正则表达式:
[Ll] 匹配 L 或 l,问号表示前面的字符(斜杠)是可选的。
Try this regex:
[Ll] matches either L or l, question mark means the previous character (slash) is optional.
除了@milan的回答之外,您还可以指定 NC 标志,这使得重写规则不区分大小写。
参考
Further to @milan's answer, you could also specify the
NC
flag, of which makes the rewrite rule not case sensitive.Reference
例如:
但我必须问,为什么?为什么不直接选择一个 URL 并坚持使用呢?您希望人们手动输入 URL 吗?
For example:
But I must ask, why?? Why not simply choose one URL and stick with it? Do you expect people to enter the URL manually?
应该做。 NC 表示不区分大小写,而 ?使斜杠可选。
Should do it. NC is for case insensitivity and ? makes the slash optional.