I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/
Now i want to redirect a particular category blogs to a different domain. The URL Scheme on that other domain is similar.
Please suggest me how 开发者_开发知识库can i do it using .htaccess
Assuming you're using Apache the solution is to use mod_rewrite. The following in your .htaccess should achieve what you're after. I'm assuming that %YEAR% is four numerals and %MONTH% is two numerals, adjust accordingly if this is not the case.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(/\d{4}/\d{2}/)([^/]+)(/.*)$
RewriteCond %2 ^category1|category2|category3|category5$
RewriteRule ^(.*)$ http://other.example.com$1 [redirect=permanent,last]
Explanation of each line:
- Enable mod_rewrite
- Check if the url is /four numerals/two numerals/anything/anything else
- If the above pattern matched then check if the text captured by the second set of brackets matches any of the word separated by pipes
- If the above condition matched then redirect to the same path at the server other.example.com
精彩评论