开发者

.htaccess redirect only URLs contain number and tag at end

I want to redirect every URLs 开发者_C百科contain number at end to subdomain :

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

or

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

and redirect urls contain "tag", example :

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

or

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

and not redirect URLs contain strings like this :

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


Construct your RewriteRules with regular expressions to only match the number URLs:

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

Likewise for the tag URLs:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜