0

我的主页url是这样的http://mysite.com/sub/

我只是想让它重定向到这样的新url东西http://mysite.com/sub/home?lang=en

这是我的code

Redirect 301 /sub/ /sub/home?lang=en

问题/错误:

新的url变成了这样http://mysite.com/sub/home?lang=enhome

之后有不必要的home连接en

我怎样才能删除这个?还是我的代码有问题?

不知道可能已经有类似的问题了

4

1 回答 1

1

This is because the Redirect directive "connects" 2 path nodes, and you've got one inside the other (/sub/home is inside /sub). For example, if the directive looks like this:

Redirect 301 /a /b

This means when someone requests http://mysite.com/a/foo/bar they get redirected to http://mysite.com/b/foo/bar. What happens when you get redirected to /sub/home is that you get redirected again because /sub/home matches the pattern /sub, and the home gets appended, thus /sub/home?lang=enhome.

You can try using RedirectMatch instead, which doesn't "connect" path nodes:

RedirectMatch 301 ^/sub/?$ /sub/home?lang=en

Or mod_rewrite:

RewriteEngine On
RewriteRule ^/?sub/?$ /sub/home?lang=en [L,R=301,QSA]
于 2012-12-27T08:31:58.327 回答