Redirect from document root folder to subfolder

August 16, 2015 3.6k views
Getting Started Apache

How can I redirect from to ? My (Mediawiki-based) site resides in /var/www/html/w .

The makeshift solution I am currently using is to put an index.php file in /var/www/html/ with “header( ‘Location:’ );”, but this clearly isn’t the best solution, and a user who navigates to is redirected to instead of to .

I have experimented quite a bit with /etc/apache2/sites-enabled/000-default.conf and putting an .htacces file in /var/www/html/ , but I can’t seem to get it right :-)

I would be grateful for your help.


2 Answers

You can try this .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteRule ^(/)?$ w [L]

You must have mod_rewrite enabled under apache service…

Thanks, I did an “a2enmod rewrite”, restarted apache2 and put the .htaccess file you suggest in /var/www/html/, but the browser just shows a directory listing for the document root directory.

Have another answer? Share your knowledge.