301使用.htaccess重定向不适用于多个参数

时间:2014-03-05 16:09:31

标签: php apache .htaccess mod-rewrite redirect

我实际上想将旧网站网址重定向到新网站网址。

我已将1重定向正常工作

例如

http://www.abc-old.com/test to http://www.abc-new.com/test123

但问题是当我有多个slu or或参数时它对我不起作用

喜欢

我想重定向

http://www.abc-old.com/test1/test2 to http://www.abc-new.com/test1

但它重定向为

 http://www.abc-old.com/test1/test2 to http://www.abc-new.com/test1/test2

下面是我的相同代码

Redirect 301 /test1/test2 http://www.abc-new.com/test1

请帮我理清这个

3 个答案:

答案 0 :(得分:1)

如果.htaccess文件看起来像/或httpd.conf包含它,它应该可以工作。

Options +FollowSymLinks
RewriteEngine on
Redirect 301 /test1/test2 http://www.abc-new.com/test1

也许这可能很有趣。

http://www.internetmarketingninjas.com/blog/search-engine-optimization/301-redirects/

答案 1 :(得分:0)

您可以在旧主机的根目录中使用此规则.htaccess:

RedirectMatch 301 "/test1/test2(/.*)?$ http://www.abc-new.com/test1$1

答案 2 :(得分:0)

有些我怎么解决它但仍然混淆为什么这件事情很开心?

例如我有3个网址

http://www.old.com/test1/
http://www.old.com/test1/test2
http://www.old.com/test1/test2/test3

我在.htaccess中创建了301重定向,如

Redirect 301 /test1/ http://www.new.com/test1
Redirect 301 /test1/test2/ http://www.new.com/test2
Redirect 301 /test1/test2/test3 http://www.new.com/test3

在这种情况下

我正在请求

http://www.old.com/test1/ is redirected to http://www.new.com/test1

,而

http://www.old.com/test1/test2 is redirected to http://www.new.com/test1/test2/

在这种情况下,当服务器执行.htaccess时,而不是我的第二个url重定向首先是工作和附加参数传递test2所以它新的重定向是http://www.new.com/test1/test2

我已经编写了这样的代码

Redirect 301 /test1/test2/test3 http://www.new.com/test3
Redirect 301 /test1/test2/ http://www.new.com/test2
Redirect 301 /test1/ http://www.new.com/test1

它开始工作了。我真的不明白为什么我的第一个代码不起作用,我使用过wordpress CMS,是否需要任何配置?