6

I have setup a virtual host which specifies a default file to load when the URL is called.

The problem I have is that I need that default DirectoryIndex file to appear in the URL.

So when I go to: www.mysite.co.uk, I want www.mysite.co.uk/app.php to appear in the URL.

How can I achieve this using my virtual host configuration within my apache.conf file?

Here is my current code:

<VirtualHost *:80>
ServerName *.mysite.co.uk
DocumentRoot "/var/www/html/mysite/web/"
DirectoryIndex app.php
</VirtualHost>

1 Answer 1

6

I am not sure if you are able to force the browser to show the default page, as that sort of defeats it's purpose. The best idea I could think of would be to leave the default as index.html, and use mod_rewrite to direct index.html to app.php.

This should work for the default index (http://domain.com/) and show desired url in browser (http://domain.com/app.php)

<VirtualHost *:80>
ServerName *.mysite.co.uk
DocumentRoot "/var/www/html/mysite/web/"
DirectoryIndex index.html

RewriteEngine on
RewriteRule ^index\.html$ app.php$1 [L,R=301]

</VirtualHost>
1
  • 2
    Instead of the RewriteRule, RedirectMatch permanent ^/$ /app.php will also work. Jan 5, 2015 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.