301重定向所有不存在的链接

时间:2012-09-03 09:01:31

标签: .htaccess redirect redirecttoaction

我已经浏览了其他帖子,但由于我不是.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]

1 个答案:

答案 0 :(得分:0)

你的代码将创建一个无限循环(你正在重写同一个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]