0

Right now, I have my DocumentRoot set to /var/www/html and my URL is domain.com.

My logical ordering of things is that I have mainpages for domain.com all located in /var/www/html/{index.html,about.html,...}. I also have "unrelated" sub-sites which I'd like to link from domain.com/subsite1 domain.com/subsite2.

Is there any way I can move the domain.com top-pages to a folder, without having to move subsite1 and subsite2 inside that folder. I also don't want to hard-code any aliases to subsites or to the top-pages of my domain.

Essentially, I want to collect the scattered html files in my DocumentRoot into a folder, but still have them accessible without the URL containing a directory. I also want existing subdirectories of my DocumentRoot to stay where they are and retain the same URL.

1
  • Maybe something like telling Apache, "if it is not found in DocumentRoot, look here"?
    – jaynp
    Oct 29, 2014 at 21:47

1 Answer 1

1

If I understood correctly, you have tow options, one change the URL internally within the server, and the rest of the internet doesn't know it's been changed, and other redirect all requests to the new URL(s).

For the first option you'd use mod_rewrite.
Eg.

RewriteEngine On
RewriteRule ^/page\.html$ /newdir/page.html [L]

Or a generic rule if file not exist

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteRule (.*) /newdir/$1 [L]

If you want to redirect all requests to the new URL(s), then you can use Redirect

Eg.

Redirect 301 /page.html /newdir/page.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .