apache - RewriteEngine 每次都在 <IfModule mod_rewrite.c> 中打开?

标签 apache .htaccess mod-rewrite url-rewriting webserver

我想知道当它嵌入 IfModule mod_rewrite.c 时,我是否只能在我的 htaccess 中使用 RewriteEngine On 一次,还是我必须每次都使用它,因为它是嵌入的?

请参阅下面的示例。谢谢

<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} /?author   [NC]
RewriteRule .* - [F]
</ifModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} g=  [NC]
RewriteRule ^(.*)$ - [F,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

最佳答案

您应该能够对所有重写代码进行一次检查。

我从您的代码中怀疑您正在使用的站点将无法正常运行,或者根本未启用 mod_rewrite。在这种情况下,我会完全省略对 mod_rewrite 的检查,如果未启用,则让网络服务器失败。

如果您最终遇到将代码安装在未启用 mod_rewrite 的网络服务器上的情况,那么调试和查明确切问题会容易得多。

关于apache - RewriteEngine 每次都在 <IfModule mod_rewrite.c> 中打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17636382/

相关文章:

android - 如何在使用由 Apache 提供支持的库的 Android 应用程序中添加 Apache License 2.0

python - Django 中的 MySQLdb 错误

php - Wordpress:413 请求实体太大

regex - 无法使用 htaccess 中的重写将 HTTP 重定向到 HTTPS

php - 如何将错误的查询字符串重定向到自定义错误页面+ 404 状态

https 子域重定向的 Apache 重写规则

eclipse - Apache Tomcat v8 未在 Eclipse Juno 中显示

php - 如何让 .htaccess 将 REQUEST_URI 附加到 404 页面

javascript - 内部问号或 angularjs 的 url 出现问题

apache mod_rewrite,简单的问题