【问题标题】:.htaccess Rewrite rules for stopping executing.htaccess 重写规则以停止执行
【发布时间】:2013-01-30 20:23:02
【问题描述】:

我的大多数 htaccess 规则将未签名的用户重定向到 index.html
但是当我将它们重定向到index.html 时,所有这些规则也会针对该页面重新运行。我需要为访问索引文件的用户运行最少的规则集。

很明显[L] 停止了 htaccess 规则的运行。

解决这个问题的更好方法是什么?这是一种正确的方法还是您有更好的建议?

RewriteCond %{REQUEST_URI} index\.html
RewriteRule ^(.*)$ index.html [L]

我的完整 htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} (\/onefolder|\/secondfolder) [NC]
    RewriteCond %{REMOTE_ADDR} !111\.22\.33\.44 [NC]
    RewriteCond %{REQUEST_URI} !(index\.html) [NC]
    RewriteRule ^(.*)$ index.html [F]

    RewriteCond %{HTTP_USER_AGENT} oneagent|otheragent [NC]
    RewriteCond %{REQUEST_URI} !(index\.html) [NC]
    RewriteRule ^(.*)$ index.html? [R=301,L]

    RewriteCond %{HTTP_USER_AGENT} betteragent|otherbetterganet [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(index\.html) [NC]
    RewriteRule ^(.*)$ index.html? [R=301,L]

    RewriteCond %{HTTP_COOKIE} !username [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\/importantone|\/somefolder|index\.html) [NC]
    RewriteRule ^(.*)$ index.html [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    你可以做一些事情。如果您想简单地停止为 index.html 重写,您可以在规则的最顶端做一些类似于您所拥有的(但更简单)的事情:

    RewriteRule ^/?index.html$ - [L]
    

    - 只是为了“通过”,本质上是让它在那里停止重写。

    或者,您可以通过将其添加到规则顶部来完全防止循环:

    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    

    做类似的事情,但检查是否有任何类型的内部重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多