ModRewrite 重定向例外?
我在 .htaccess 文件中使用以下几行从每个 /something
重定向到 /#!/something
网址。所以我重定向到一个哈希,这样我就可以用 JavaScript 捕获它。这工作得很好……
RewriteEngine on
# not existing file (images, css, etc)
RewriteCond %{REQUEST_FILENAME} !-f
# no query parameters
RewriteCond %{QUERY_STRING} =""
# not /
RewriteCond %{REQUEST_URI} !^/$
# R=redirect, NE=dont escape #, L=last rule
RewriteRule ^(.*)$ /#!/$1 [R,NE,L]
# same but with query parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /?%{QUERY_STRING}#!/$1 [R,NE,L]
有没有办法对此有例外。例如,当我输入 www.test.com/stats
时,我不希望发生这种情况!
I'm using the following few line in my .htaccess file to redirect from every /something
to /#!/something
url. So I'm redirecting to a hash so I can catch it with javascript. That works perfectly fine …
RewriteEngine on
# not existing file (images, css, etc)
RewriteCond %{REQUEST_FILENAME} !-f
# no query parameters
RewriteCond %{QUERY_STRING} =""
# not /
RewriteCond %{REQUEST_URI} !^/$
# R=redirect, NE=dont escape #, L=last rule
RewriteRule ^(.*)$ /#!/$1 [R,NE,L]
# same but with query parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /?%{QUERY_STRING}#!/$1 [R,NE,L]
Is there a way to have an exception on that. E.g. when I enter www.test.com/stats
I don't want that to happen!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将其添加到您想要例外的所有规则前面:
以及您不想重定向的任何其他 URI。您可以将它们全部包含在同一个正则表达式中:
Just add this in front of all the rules you want the exception on:
And any other URI's you don't want to redirect. You can include them all in the same regex: