1

In my document root, I have to directories: home and foobar, both with their own index.html files.

How can I set it up so that when someone visits my site at example.com, they see the contents on home/index.html?

I tried using an index.php with a redirect in document root, as well as a .htaccess redirect, but both of them change the URL in the browser to example.com/home/, which I would like to ideally avoid.

1
  • If you need the 'big gun': mod_rewrite First check if requested file is present. If it is, return it. If not, rewrite to '/home'. Sorry no code example at hand right now.
    – Roman
    Sep 24, 2012 at 16:23

3 Answers 3

0

Why don't you just move the contents of home up one directory?

2
  • Because the contents of each directory in my document-root belong to a different git repo. Having the contents of home up one level will cause me to commit other projects (in the wrong repo) as well when I commit the contents of home.
    – Ayush
    Sep 24, 2012 at 15:30
  • If they are inteded to work together, you can actually put one in the other using Git Submodules.
    – SteeveDroz
    Oct 4, 2019 at 5:23
0

What about the simplest solution: Creating a simple PHP file that includes the document?

<?php
   include("html/index.html");
?>
0

Here are two solutions to your problem.

1. Using virtual hosts

You probably have a VirtualHost that points to your website. Edit it this way:

<VirtualHost *:80>
    DocumentRoot /path/to/your/directory/home # add /home at the end
    ServerName example.com
    <Directory /path/to/your/directory>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Then don't forget to restart apache2 (or httpd)

2. Using .htaccess

Add this in your .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/home
RewriteRule ^(.*)$ home/$1

Note that /foobar will be completely impossible to reach exept by an include from your /home directory.

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.