0

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?

nicovon
  • 7
  • 7
  • Possible duplicate of [Redirect site with .htaccess but exclude one folder](https://stackoverflow.com/questions/3414015/redirect-site-with-htaccess-but-exclude-one-folder) – wp78de Jul 10 '19 at 20:23

1 Answers1

0

Check this rule in your .htaccess file

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^site4 [NC]
RewriteRule (.*) https://www.mynewsite.com/ [R=301,L]
JarekBaran
  • 1,311
  • 2
  • 7
  • 12
  • I created some redirects from the page of the old site to the corresponding page of the new site. Where should I place them exactly? Before the code you suggested? – nicovon Jul 10 '19 at 21:53
  • Add new redirects after the `RewriteBase /` line and before the last rule that redirect everything else (except site4). – JarekBaran Jul 17 '19 at 20:23
  • I realized now that the `RewriteBase /` line is commented. The line has never been uncommented. There is a suggestion but I don't know what it means: If your site is running in a VirtualDocumentRoot at http://example.com/, uncomment the following line. – nicovon Jul 18 '19 at 10:15