开发者

How to setup .htaccess redirect for particular category blogs (wordpress)

开发者 https://www.devze.com 2022-12-10 04:44 出处:网络
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/

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:

  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
0

精彩评论

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