如何将多个动态URL重定向到单个静态URL

时间:2014-05-14 11:36:16

标签: php .htaccess redirect

我想将此404错误网址重定向到静态网址。这怎么可能。请帮忙..

网址http://www.takeshiyashima.com

/us/my-blog?catid=1&id=404:my-thought-of-the-day-problem-of-traditional-education  
/ja/resources?id=366:video-clip  
/ja/resources?id=364:mortgage-reset-second-big-wave 
/us/my-blog/65-investment?catid=230&id=230:wealth-cycle9 
/us/resources?catid=72&id=354:fractional-reserve-banking
/us/my-blog?catid=1&id=432:petrodollar-system-inevitable-economic-collapse-and-possibility-of-world-war-iii 
/tw/?catid=0&id=539 
/tw/?catid=0&id=519 
/ja/resources?catid=72&id=357:flaw-of-401k 
/us/my-blog/65-investment?catid=301&id=301:my-recent-real-estate-deal-and-why-i-am-investing-in-real-estate 
/tw/?catid=0&id=502
/ja/?catid=0&id=516 

我在谷歌网站管理员中有561错误。请帮我重定向此类网址。

2 个答案:

答案 0 :(得分:0)

使用 .htaccess 重定向

ErrorDocument 404 http://example.com/404/

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /pages/errors/404.php [L]

博客:Redirect your 404 error to a Custom Page
Stack Overflow上的Answer

答案 1 :(得分:0)

如果您想将不存在的页面的所有请求重定向到http://example.com/404.php,只需将以下行添加到.htaccess文件中:

ErrorDocument 404 http://example.com/404.php

但是,在没有明显更改网址的情况下,提供404.php页面通常会更好。这更容易:

ErrorDocument 404 /404.php

请注意,对于后一种解决方案,这些网页仍会显示为404错误,例如在Google的网站管理员工具中。但是,这实际上是一个的东西,因为它可以让你告诉丢失的页面除了重定向。访问这些网页的用户仍会看到您的404.php页面,只是在丢失的网页网址下提供,并且会显示404状态代码。

有关更多信息,请参阅Apache文档中的Custom Error Responses


聚苯乙烯。请注意,如果您的404错误是由某个应用程序框架或脚本生成的(即脚本已成功执行,但故意返回404响应,例如因为它无法找到),这将工作数据库中请求的资源)。在这种情况下,解决方案将取决于具体的应用程序或脚本。