Home > database >  Redirect generic page to specific
Redirect generic page to specific

Time:09-29

Im trying to redirect any page that starts with the directory blog to a specific page. Here is what I what to do:

test.com/blog/ => test.com/news/
test.com/blog/anything => test.com/news/

Its working well with the root blog/, but it does work well for the articles. What should I do?

RewriteEngine On
Redirect 301 ^/blog/?$ https://test.com/news$

CodePudding user response:

RewriteEngine and Redirect are directives from 2 different module. Don't mix up those. Moreover you don't need $ in target as regular expression is only used for matching a pattern.

You can use following rule inside the /blog/.htaccess file:

RewriteEngine On

RewriteRule ^ /news/ [L,R=301]

This will redirect any request that starts with /blog/ to /news/.

  • Related