Ad
How To Setup .htaccess Redirect For Particular Category Blogs (wordpress)
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
Ad
Answer
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
Ad
source: stackoverflow.com
Related Questions
- → Laravel 5: Apache php http authentication
- → Htaccess negation
- → OctoberCMS error in frontend - frontend is not accessible firing error "Default value for parameters with a class type hint can only be NULL"
- → How to give access execute specific php file in server?
- → 301 Redirection from no-www to www in wordpress
- → Cyclical redirection at the start laravel 5 project
- → Can't route in Laravel framework
- → How to benefit of prerender.io services if my Apache server doesn't allow a proxy
- → OctoberCMS installation MYSQL error
- → Redirect 301 htaccess prestashop
- → Permissions "public" folder Laravel
- → .htaccess affect other file url
- → How i can redirect from "www.mywebsite.com////" to "www.mywebsite.com"?
Ad