2
votes

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?

1
can you be more precise with what you're expecting? you want the folder contact-us under domain.com/index.html? - Diogo Jesus
@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

1 Answers

0
votes
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.