0

我想在 htaccess 中做一些重定向。我将详细解释我正在尝试做什么,最后我会告诉你我的问题,所以如果你不想要很多解释,只需向下滚动即可。

因此,为了让您了解我在做什么,这里有一个示例:如果我输入www.mysite.com/oldpage它应该将我重定向到www.mysite.com/new page。为此,我使用了:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

Redirect /oldpages http://www.mysite.com/newpages

问题是我想将它用于不止一页。所以我想要:

mysite.com/oldpage/firstarticle 

重定向到

mysite.com/newpage/firstarticle

和所有文章一样。我想重定向所有像:

Redirect /oldpages http://www.mysite.com/newpages
Redirect /oldpages/firstarticle http://www.mysite.com/newpage/firstarticle
Redirect /oldpages/secondarticle http://www.mysite.com/newpage/secondarticle

但是我有一个冲突,因为Redirect /oldpage适用于每种情况。

这就是为什么(这就是我不该做什么!!!)我需要使用如下一般规则:

Redirect /oldpage/(*) http://mysite.com/newpage/(*)
Redirect /oldpage/(any numeric characters-don't need them)/(*) http://mysite.com/NEWSINGLEPAGE/(*)

而不是 (*) 它应该是任何字符,但在新链接中使用它们。

有人知道如何使此重定向超过一页吗?

感谢您的时间!

!!!! 我不知道这是否可能,但如果我可以在 HTACCESS 中使用 IF 语句会更好......类似于:

if (adress is /redirect) Redirect to newpage.html;
  else if (adress is /redirect/(some number)/(.*)) Redirect to NEWSINGLEPAGE/$1.html
       else if (adress is /redirect/(.*)) Redirect to newpage/$1.html
4

2 回答 2

1

改变

Redirect /oldpage/(*) http://mysite.com/newpage/(*)

RedirectMatch /oldpage/(*) http://mysite.com/newpage/$1
于 2013-05-23T12:25:04.763 回答
0

尝试这个

RewriteRule ^oldpage/(.*)$ /newpage/$1 [R=301,L]
于 2013-05-23T12:57:08.130 回答