【问题标题】:Using .htaccess to redirect all pages except three使用 .htaccess 重定向除三个页面之外的所有页面
【发布时间】:2019-01-03 04:43:18
【问题描述】:

我正在使一个网站永久脱机,但在它关闭之前我会在其上显示一个启动页面一两个星期。如何编辑我的 .htaccess 文件以显示该启动页面?它需要允许页面本身(根目录)以及 /images 目录中的两个图像。

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    将以下配置放入位于您网站根目录的.htaccess

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/splash.html$
    RewriteCond %{REQUEST_URI} !^/images/usedimage.png$
    RewriteCond %{REQUEST_URI} !^/images/anotherusedimage.png$
    RewriteRule .* /splash.html [R=301,L]
    

    【讨论】:

    • 刚试了一下,Chrome 报告重定向循环(错误 310)。
    • @StevenH 请检查splash.html 是否列在RewriteCond 的列表中...如果您确定,请尝试删除/ 中的前导斜杠RewriteCond
    • 是的,我确认splash.html 既位于根目录中,又位于RewriteCond 中。我尝试删除领先的/,但我仍然得到一个重定向循环。除了你给我的代码(为我的文件名编辑)之外,.htaccess 文件中没有任何内容。
    • @StevenH 重定向循环意味着,与您的splash.html 对应的RewriteCond 不匹配。不太清楚为什么会这样 - 正如我的回答中所写,该设置在我的计算机上运行。
    • 啊,我明白了——我必须在RewriteRule 中的splash.html 前面加上一个/。那成功了。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 2020-03-11
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 2012-10-29
    相关资源
    最近更新 更多