我将如何编写一个 RewriteRule 来对一个文件进行例外处理

发布于 2024-09-04 02:52:35 字数 272 浏览 1 评论 0原文

目前我的 .htaccess 文件中有这样的内容:

Options +FollowSymLinks  
RewriteEngine On    
RewriteRule ^(.*)\.html$ index.php?pagename=$1&%{QUERY_STRING}

html 文件名被重写为页面名查询字符串。

然而,我试图允许访问一个特定的静态 html 文件,因此我需要以某种方式覆盖规则或例外。

谢谢你的帮助。

I currently have this in my .htaccess file:

Options +FollowSymLinks  
RewriteEngine On    
RewriteRule ^(.*)\.html$ index.php?pagename=$1&%{QUERY_STRING}

The the html file name is rewritten to the pagename query string.

However I'm trying to allow access to one particular static html file, so somehow I need to overwrite the rule or make an exception.

Thanks for you help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

聽兲甴掵 2024-09-11 02:52:35
  1. 没有必要自行附加QUERY_STRING;如果没有的话,你会留下一个杂散的 &,并且 mod_rewrite 已经有一个工具可以做得更好:

    RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]

  2. 您可以使用前面的 RewriteCond 来控制 RewriteRule。例如:

    RewriteCond %{REQUEST_URI} !^/staticpage.html$
    RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]

  3. 另一个有用的模式是 RewriteCond %{REQUEST_FILENAME} !-f只要 URL 与文档根目录中的现有常规文件相匹配,就会绕过以下 RewriteRule 任何

  1. No point appending QUERY_STRING yourself; you'll leave a stray & if there isn't any, and mod_rewrite already has a tool to do it better:

    RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]

  2. You can control a RewriteRule with a RewriteCond that precedes it. For example:

    RewriteCond %{REQUEST_URI} !^/staticpage.html$
    RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]

  3. Another useful pattern is RewriteCond %{REQUEST_FILENAME} !-f which will bypass the following RewriteRule any time that the URL would have matched an existing regular file in the docroot.

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