Home > Software engineering >  Redirect all pages of a parent page to another parent page
Redirect all pages of a parent page to another parent page

Time:07-30

I want to redirect subpages of a parent page to another parent page like this:

/parent-1/sub-1  redirect to   /parent-2/sub-1
/parent-1/sub-2  redirect to   /parent-2/sub-2
/parent-1/sub-3  redirect to   /parent-2/sub-3
/parent-1/sub-4  redirect to   /parent-2/sub-4

and so on i want to do these redirects without no plugin just using htaccess.( domain is not changed). i know how to redirect a single page to another but there are over 150 pages is there a way to redirect all pages

CodePudding user response:

This probably is what you are looking for:

RewriteEngine on
RewriteRule ^/?parent-1/(. )$ /parent-2/$1 [R=301,L]

That rule will redirect all "subpages". If you need to make exceptions, then an additional rule for those could be implement before, so above the RewriteRule in that sequence.

You can implement such such rules in the central http server's host configuration. Alternatively you can use a distributed configuration file (".htaccess"), if you have enabled the interpretation of such files for the http host and the location.

In general it is a good idea to start out using a R=302 temporary redirection and to only change that to a R=301 permanent redirection once everything works as desired. That prevents nasty caching issues on the client side. Also remember to always test using a fresh, anonymous browser window or to clear your browsers cache.

  • Related