ModRewrite 重定向例外?

发布于 2024-12-28 13:26:54 字数 650 浏览 5 评论 0原文

我在 .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 技术交流群。

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

发布评论

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

评论(1

偏爱你一生 2025-01-04 13:26:54

只需将其添加到您想要例外的所有规则前面:

RewriteCond %{REQUEST_URI} !^/stats

以及您不想重定向的任何其他 URI。您可以将它们全部包含在同一个正则表达式中:

RewriteCond %{REQUEST_URI} !^/(stats|something|example|test)

Just add this in front of all the rules you want the exception on:

RewriteCond %{REQUEST_URI} !^/stats

And any other URI's you don't want to redirect. You can include them all in the same regex:

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