重定向301到htaccess不起作用

时间:2012-12-14 09:27:09

标签: php .htaccess

  

可能重复:
  htaccess 301 redirect not working

当有人想要test.php to newpage.php时,我需要重定向。

我的htaccess包含:

Options All -Indexes
RewriteEngine on
RewriteRule ^contact.shtml$ contact.php [NC]

RewriteRule ^news/(.*)/(.*)$ news_main.php?id=$1&title=$2 [L]

Redirect /test.php http://mydomain.com/newpage.php

但它不起作用。这里有什么不对吗?如果我们这样请帮助我。

2 个答案:

答案 0 :(得分:2)

如果重定向很重要,则应将其放在与重写模块相关的部分上方。

此外,如果您想要301(永久)重定向,则需要指定它。默认情况下,重定向为302。

除此之外,一切看起来都在我眼前。

# Core Module
Options All -Indexes

# Alias Module
Redirect 301 /test.php http://mydomain.com/newpage.php

# Rewrite Module
RewriteEngine on
RewriteRule ^contact.shtml$ contact.php [NC]
RewriteRule ^news/(.*)/(.*)$ news_main.php?id=$1&title=$2 [L]

答案 1 :(得分:0)

您可以直接在.htaccess文件中添加代码 -

重定向301 /test.php http://mydomain.com/newpage.php