如何使用.htaccess重定向网页

时间:2011-01-25 10:13:45

标签: .htaccess

我的htaccess中有这段代码,但它无效。

RewriteEngine on RewriteBase /
RewriteRule viewtopic\.php?t=([^/]+)$
http://newdomain.com/viewtopic.php?t=$1

如何将viewtopic.php?t = 1的页面重定向到viewtopic.php?t = 2000到我的新域名?

3 个答案:

答案 0 :(得分:0)

您需要在模式中转义.?

RewriteEngine on 
RewriteBase / 
RewriteRule viewtopic\.php\?t=([^/]+)$ http://newdomain.com/viewtopic.php?t=$1 [L,R=permanent]

答案 1 :(得分:0)

除了Daniel Gehriger的解决方案之外,在行尾添加[L,R=301]。这将使Apache向您的客户端发送301 Page Moved代码,通知它该页面确实已永久移动。这将导致搜索引擎,RSS阅读器等更新其链接(如果它们足够聪明)。

答案 2 :(得分:0)

只是因为这里有人有问题,我使用此代码将html页面重定向到子域:

RewriteEngine on 
RewriteBase / 
RewriteRule sharecrypt.html http://cryptool.sharepirate.com [L,R=301]
相关问题