【问题标题】:.htaccess redirect but not always.htaccess 重定向但并非总是如此
【发布时间】:2013-03-12 21:06:16
【问题描述】:

我在制作 .htaccess 文件时遇到了一些问题。我将图像和 .css 文件存储在 /inc/ 文件夹中,例如 http://example.com/inc/style.css

现在,我希望所有不以 http://example.com/inc/ 开头的 URL “重定向”到 http://example.com/,因此如果您调用 http://example.com/hello/fire/,该 URL 应该仍在您的地址栏中,但它会加载 http://example.com/。因此,地址栏中的 URL 不得更改。

有人知道这是怎么工作的吗?

马克

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    试试:

    RewriteEngine On
    
    # This prevents the rewrite engine from looping
    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    
    # If URI starts with "/inc/" do nothing (passthrough)
    RewriteRule ^/?inc/ - [L]
    
    # Otherwise if URI is at least 1 character (not "/"), rewrite to "/"
    RewriteRule . / [L]
    

    【讨论】:

      猜你喜欢
      • 2013-11-15
      • 2019-11-29
      • 2015-07-01
      • 2013-10-20
      • 2019-12-07
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      相关资源
      最近更新 更多