【问题标题】:301 Redirect ALL none existing links301 重定向所有不存在的链接
【发布时间】:2012-08-28 00:18:22
【问题描述】:

我浏览了其他帖子,但由于我不是 .htaccess 向导,所以我不太清楚如何更改代码以满足我的需要。

基本上我有一个控股页面。我正在构建的网站的页面,只是希望将任何不存在的链接重定向回保留页面。

我想它会是这样的吗?

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$ [NC]
#if not root
RewriteCond %{REQUEST_URI} !^/?$ [NC]
#redirect
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]

【问题讨论】:

    标签: .htaccess redirect redirecttoaction


    【解决方案1】:

    您的代码将创建一个无限循环(您正在重写相同的 url),请尝试此操作(并确保 holdingpage.php 确实存在,否则您将获得一个无限循环):

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$ [NC]
    #If the requested file does not exists
    RewriteCond %{REQUEST_FILENAME} !-f
    #Redirect to the holding page
    RewriteRule . http://www.example.co.uk/holdingpage.php [L,R=301]
    

    【讨论】:

    • 不幸的是,这仍然对我不起作用...您能想到任何其他可能不起作用的原因吗?我仍然只是得到一个 404 页面。我做了一个简单的重定向来说明如果有人输入 /test/ 它会重定向到 www.example.com/apples 并且这有效。所以这不是配置问题。我想它一定是纯粹的语法......
    • 你能把你的 htaccess 文件上的内容贴出来
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    相关资源
    最近更新 更多