【问题标题】:Redirect not working htaccess重定向不起作用htaccess
【发布时间】:2015-03-07 01:51:24
【问题描述】:

我的.htaccess 文件如下所示:

`<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule .* /maintenance.html [R=302,L]
</IfModule>`

但我的任何.htm/.html 页面似乎都没有发生重定向

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect http-redirect


    【解决方案1】:

    删除RewriteCond %{REQUEST_FILENAME} !-f,因为它正在停止任何受影响的现有文件。

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|CSS|js)$ [NC]
    RewriteRule !^maintenance\.html$ /maintenance.html [NC,R=302,L]
    

    确保这是您的根目录 .htaccess 中的第一条规则

    【讨论】:

    • 我将 .htaccess 文件更改为 &lt;IfModule mod_rewrite.c&gt; RewriteEngine on RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif)$ [NC] RewriteRule !^maintenance\.html$ /maintenance.html [NC,R=302,L] &lt;/IfModule&gt; 但重定向仍然不起作用。 :-( 我不太确定,这个问题只存在于.htaccess 文件中,因为即使我在index.html 和其他现有页面中进行了更改,但它没有反映,尽管我添加了正确显示的新页面。
    • 此外,如果我删除 RewriteCond %{REQUEST_FILENAME} !-f,我的 maintenance.html 的 CSS 将无法正确加载,而且其他页面根本不会重定向!
    • 添加了处理 CSS/js 问题的规则。确保这是您在新浏览器上测试时的第一条规则。
    猜你喜欢
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 2013-01-30
    • 2013-04-06
    • 2017-06-30
    相关资源
    最近更新 更多