限制重写规则以排除某个目录
当重写规则允许我们使用 ID 号创建友好的 URL 时。这个故事只是通过身份证号码拉出来的,所以最后的文字并不重要。
RewriteRule ^news/([0-9]+)$ /news/$1/ [R=301,L]
RewriteRule ^news/([a-zA-Z0-9_-]+)/.*$ /news/story.php?id=$1
当 /news/images/ 中链接的任何文件也会被重定向时,我们的问题就出现了。因此,任何显示来自 /news/images/ 的图像的内容都不起作用。
有人可以帮我吗?我们如何限制重写,使其显示“如果它位于 /images/ 子目录中,则不要重写路径”?
When a a rewrite rule to allow us to make friendly URL's with an ID number. The story is only pulled through the ID number, so the text at the end doesn't really matter.
RewriteRule ^news/([0-9]+)$ /news/$1/ [R=301,L]
RewriteRule ^news/([a-zA-Z0-9_-]+)/.*$ /news/story.php?id=$1
Our problem comes when any file linked within /news/images/ , it gets redirected as well. So anything that displays an image from /news/images/ doesn't work.
Can someone help me out? How can we limit the rewrite so that it says "If it's in the /images/ subdirectory, don't rewrite the path"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以采取简单的路线,如果文件存在则避免重写:
或者,如果您想进行目录检查,以防资源请求没有指向真实文件,但应该直接生成 404 响应,您可以尝试以下操作:
You could take the simple route and just avoid the rewrite if the file exists:
Alternatively, if you wanted to do the directory checking in case the resource request didn't point to a real file, but should directly generate a 404 response, you can try the following: