2

I have successfully set the DocumentRoot for a given server names:

<VirtualHost *:80>
 DocumentRoot "/var/www/html/domain1"
 ServerName www.domain1.com
 ServerAlias *.domain1.com
#Other directives here
</VirtualHost>

I can't seem to figure out, how to move the subfolders ie."www.domain1.com/contact-us" so it presents index.html located in "/var/www/html/domain1".

I tried adding the alias for the /contact-us in the VirtualHost instructions:

<VirtualHost *:80>
     DocumentRoot "/var/www/html/domain1"
     ServerName www.domain1.com
     ServerAlias *.domain1.com
    #Other directives here
     Alias /contact-us /var/www/html/domain1
    </VirtualHost>

It doesn't work as expected.

I am thinking doing this via .htaccess in the subfolder for the domain1. How would I go around redirecting everything after the domain name to the index.html?

sredwopclub
  • 51
  • 1
  • 3
  • can you be more precise with what you're expecting? you want the folder contact-us under domain.com/index.html? – Diogo Jesus Mar 06 '18 at 12:16
  • @DiogoJesus Sure. The end goal is to redirect every subdirectory to the main index.html in the DocumentRoot set up via the virtual host ("/var/www/html/domain1"). So www.domain1.com/about-us would point out to "/var/www/html/domain1/index.html, and the rest of 11 sub directories as well. – sredwopclub Mar 06 '18 at 12:50

1 Answers1

0
RewriteEngine on
RewriteRule ^subdirectory/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^about-us/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^contact/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^subfolder/(.*)$ /$1 [R=301,NC,L]

Test out this code, make sure the change the folder names.


EDIT

This must be in your .htaccess in your web directory root folder.

Diogo Jesus
  • 318
  • 4
  • 19
  • I have created a .htaccess in the /var/www/html/domain1 directory, but every time I am going to the: www.domain1.com/about-us/ it's still showing the index.html from the "default" root rather than the DocumentRoot set in the VH. The virtual host is working okay and serving correct content when going to domain1.com - it's displaying index.html from "/var/www/html/domain1" - it seems like the .htaccess is not read by apache? – sredwopclub Mar 09 '18 at 09:26
  • so you're not getting the index.hmtl from /var/www/html/domain1/subdirectory but you're getting the index from /var/www/html ? I'm confused now – Diogo Jesus Mar 12 '18 at 07:28