简体   繁体   中英

Redirect any page and folder to the homepage of the new site

I have a domain with four websites to close shortly:

  1. www.example.com (main site)
  2. www.example.com/site2
  3. www.example.com/site3
  4. www.example.com/site4

the .htaccess file of the main site, contains the following code:

Redirect 301 / https://www.mynewsite.com

In this way, if the user visits the site www.example.com/site1, he is redirected to www.mynewsite.com/site1 which does not exist and therefore the page returns a 404 error. This applies to all pages and folders of the site to be closed.

Although it is not a good practice, I would like to redirect any page and folder of all websites to be closed, to the homepage of the new site, except for the site www.example.com/site4 which must still be open to the public.

How is this accomplished? Do I have to work exclusively with the .htaccess file on the main site?

Check this rule in your .htaccess file

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^site4 [NC]
RewriteRule (.*) https://www.mynewsite.com/ [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM