htaccess RewriteRule问题
我的重写规则有问题。
我目前正在使用此规则:
RewriteRule ^([^/.]+)/?$ index.php?clip=$1
这对于以下链接效果很好,其中 $_GET['clip']
是斜杠后的值:
但不适用于那些带有点字符的字符,例如:
http://example.com/abcdefg.png
我应该如何更改 RewriteRule 以使其适用于此类链接?
I have a problem with RewriteRules.
I'm currently using this rule:
RewriteRule ^([^/.]+)/?$ index.php?clip=$1
This works fine for links as these, where $_GET['clip']
is the value after the slash:
But not for those with a dot character, like these:
http://example.com/abcdefg.png
How should I change the RewriteRule to make it work for such links?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不建议使用这种技术,因为它会导致额外的磁盘读取来检查文件是否存在......
如果您有可能,我建议您以 apache 可以从目录中知道要做什么的方式组织您的目录结构。我的框架中的示例:
i wouldn't suggest this technique because it will cause an extra disk read to check if the file is there...
if you have the possibility i would advise to organize your directory structure in a way that apache can tell from the directory what to do. example from my framework:
尝试这个代码:
这将防止它忽略真正在您的服务器上的文件。因此,只要
/abcdefg.png
存在,http://example.com/abcdefg.png
就可以工作。此外,您在重写规则中使用的正则表达式需要稍微更改,我删除了
.
因为您正在阻止它。try this code:
This will prevent it from ignoring files that are really on your server. so
http://example.com/abcdefg.png
will work, as long as/abcdefg.png
exists.Also the regex you used in the rewrite rule needs to be altered slightly, I removed the
.
as you were preventing it.您正在匹配任何不包含“/”或“.”的字符串。如果你希望匹配包含扩展名,你可以使用:
如果你不关心它:
You are matching on any string that does not contain "/" or ".". If you want the match to include the extension, you can use:
If you don't care about it: