【问题标题】:htaccess test stopped after RewriteCond is encountered遇到 RewriteCond 后 htaccess 测试停止
【发布时间】:2014-06-12 09:29:57
【问题描述】:

我想将所有http://www.mywebsite.com/other/sub/paths 重定向到http://mywebsite.com/other/sub/paths

我正在使用http://htaccess.madewithlove.be 来查看我的 htaccess url 输出,然后再在实时站点上进行操作。我可以重定向我的页面,但测试中途停止并显示以下内容:

RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$ [NC]  This condition was met
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301]
This rule was met, the new url is
http://mywebsite.com/index.php?q=sc?pract?aut The tests are stopped,
using a different host will cause a redirect

这是测试停止的错误吗? 我有以下几行未经测试(它们在测试停止的 RewriteRules 之后)

RewriteCond %{REQUEST_FILENAME} !-f     
RewriteCond %{REQUEST_FILENAME} !-d     
RewriteCond %{REQUEST_URI} !=/favicon.ico   
RewriteRule ^ index.php [L]     
# Requires both mod_rewrite and mod_headers to be enabled.  
# Serve gzip compressed CSS files if they exist and the client accepts gzip.    
RewriteCond %{HTTP:Accept-encoding} gzip    
RewriteCond %{REQUEST_FILENAME}\.gz -s  
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]    
# Serve gzip compressed JS files if they exist and the client accepts gzip.     
RewriteCond %{HTTP:Accept-encoding} gzip    
RewriteCond %{REQUEST_FILENAME}\.gz -s  
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]  
#Serve correct content types, and prevent mod_deflate double gzip.  
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]   
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

如果有任何帮助,我的网站托管在 drupal 6 上。

【问题讨论】:

    标签: .htaccess redirect drupal


    【解决方案1】:

    来自http://httpd.apache.org/docs/2.2/rewrite/flags.html

    [L] 标志导致 mod_rewrite 停止处理规则集。在大多数情况下,这意味着如果规则匹配,则不会处理更多规则。这对应于 Perl 中的最后一条命令,或 C 中的 break 命令。使用此标志指示应立即应用当前规则,而不考虑进一步的规则。

    【讨论】:

    • 那么剩下的代码没有经过测试有害吗?它会在我的网站上导致任何不容易检测到的错误吗?
    • 如果第一条规则不匹配,则 mod_rewrite 将检查下一条规则。因此,如果发生 301 重定向,则不再进行处理。但如果 301 重定向没有发生,则检查其他规则。所以他们应该被测试。测试方法是使用不带www.mywebsite.com 主机名。我觉得规则没问题。
    猜你喜欢
    • 2011-06-05
    • 2022-01-18
    • 2023-01-25
    • 2021-04-14
    • 2018-06-29
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多