2011-08-10 25 views
0

號和標籤重定向我想重定向的URL的每個數字包含在最終子域:的.htaccess只有網址包含結束

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

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

和重定向的URL包含「標籤」,例如:

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 

回答

1
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 
+0

哇!真的很快,thx – sharktech

1

建設正則表達式您的RewriteRules只匹配數量的網址:

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

同樣的標記網址:

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

哇!真的很快,thx你到 – sharktech