Struggler
Struggler

Reputation: 25

apache2 redirect from domain to subfolder

I've successfully setup MediaWiki on Ubuntu with Apache2. I can access the site via http://example.com/w/ and it redirects to http://example.com/w/index.php just fine.

I now want to be able to redirect http://example.com to ../index.php but I cannot get it working. Here is my .conf file located in /etc/apache2/sites-available:

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html/w
        DirectoryIndex index.html index.php
        ServerName site.com
        ServerAlias

        Alias /w /var/www/html/w

        <Directory /var/www/html/w>
                Options +FollowSymlinks +Indexes -Multiviews
                AllowOverride All
                Require all granted

        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

I have not modified the apache2.conf default file, and there is no .htaccess file.

Upvotes: 0

Views: 67

Answers (1)

Struggler
Struggler

Reputation: 25

I resolved the issue by adding the following lines in my apache2 conf file, between the directory tags:

            RewriteEngine on
            RewriteCond %{REQUEST_URI} ^/$
            RewriteRule (.*) /w/ [R=301]

Upvotes: 1

Related Questions