0

我正在尝试改变

http://www.myhost.com/en/team/league-of-legends/3798/destiny

http://lol.myhost.com/en/team/league-of-legends/3798/destiny

我为我的 Apache2 服务器尝试了不同的组合,包括:

RewriteCond %{HTTP_HOST}    ^www\. [NC]
RewriteRule ^/(.*)/team/league-of-legends/(.*)/(.*)  http://lol.myhost.com/$1/team/league-of-legends/$2/$3 [R=301,L]

但它似乎不起作用(我检查了一个 htaccess 测试仪)。 请问我做错了什么?

4

3 回答 3

1

通过启用 mod_rewrite 和 .htaccesshttpd.conf然后将此代码放在您的域目录.htaccess下:DOCUMENT_ROOTwww.myhost.com

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(myhost\.com)$ [NC]
RewriteRule ^[^/]+/team/league-of-legends/ http://lol.%1%{REQUEST_URI} [R=301,L,NC]
于 2013-02-12T18:40:12.687 回答
1

你可以试试这个:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?myhost\.com$ [NC]
RewriteCond %{REQUEST_URI}   ^/([^/]+)/team/league-of-legends/([^/]+)/([^/]+)/?  [NC]
RewriteRule .  http://lol.myhost.com/%1/team/league-of-legends/%2/%3    [R=301,L,NC]

永久重定向

http://www.myhost.com/en/team/league-of-legends/3798/destiny或者

http://myhost.com/en/team/league-of-legends/3798/destiny

到:

http://lol.myhost.com/en/team/league-of-legends/3798/destiny

字符串en,3798destiny假定是可变的,而teamleague-of-legends假定是固定的。

对于静默映射,R=301[R=301,L,NC]

于 2013-02-12T20:12:20.637 回答
0

看看这是否有效。如果没有,请告诉我。

RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^([^\/]*)/team/league-of-legends/(.*)$  http://lol.myhost.com/$1/team/league-of-legends/$2 [R=301,L]
于 2013-02-12T18:32:42.813 回答