需要帮助使用mod重写来重写url以省略一次出现

时间:2013-11-10 15:32:07

标签: apache mod-rewrite url-rewriting

我有以下网址

http://www.localhost/me/me/username

我想将其重写为

http://www.localhost/me/username

任何mod重写专家都可以给我一些建议吗?下面是我当前的mod重写

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

1 个答案:

答案 0 :(得分:0)

您可以在/.htaccess中尝试:

RewriteEngine On
RewriteRule ^(me/){2,}username$ /$1username [R=301,L]

这样做:

http://www.localhost/me/me/username => http://www.localhost/me/username
http://www.localhost/me/me/me/me/username => http://www.localhost/me/username

或者你似乎想要这个:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteRule ^(me/){2,}username$ /$1username [R=301,L]

后者会这样做:

http://localhost/me/username => http://www.localhost/me/username
http://localhost/me/me/username => http://www.localhost/me/username
http://www.localhost/me/me/me/me/username => http://www.localhost/me/username