views:

166

answers:

1

I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST%5FTITLE%/

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

+1  A: 

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:

  1. Enable mod_rewrite
  2. Check if the url is /four numerals/two numerals/anything/anything else
  3. 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
  4. If the above condition matched then redirect to the same path at the server other.example.com
Wes