.htaccess只重定向结尾包含数字和标签的url



我想重定向每个url结尾包含数字到子域:

http://example.com/773 to http://blog.example.com/773

http://example.com/482/comment... to http://blog.example.com/482/comment...

和重定向url包含"tag",例如:

http://example.com/tag/free-psd to http://blog.example.com/tag/free-psd

http://example.com/tag/jquery to http://blog.example.com/tag/jquery

和非重定向url包含如下字符串:

http://example.com/web or http://example.com/web/shop or http://example.com/about
RewriteCond %{REQUEST_URI}   ^/(d+)$
RewriteRule   (.*)  http://blog.example.com/%1
RewriteCond %{REQUEST_URI}   ^/(d+)/comment$
RewriteRule   (.*)  http://blog.example.com/%1/comment
RewriteCond %{REQUEST_URI}   ^/tag/(.+)$
RewriteRule   (.*)  http://blog.example.com/tag/%1

用正则表达式构造你的rewriterrules,只匹配数字url:

    RewriteEngine On
    RewriteRule ^/([0-9]+(/.+)?) http://blog.example.com/$1

标签url也是如此:

    RewriteRule ^/(tag/.+) http://blog.example.com/$1

最新更新