Point domain to specific directory via rewrites

If you have a script installed at /example.com and you want http://example.com/ to show the contents of /example without the address bar changing, you can use the following rewrites to do this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/example/
RewriteCond %{REQUEST_URI} !^/cgi-bin/awstats.pl
RewriteCond %{HTTP_HOST} ^(www\.)?example_domain
RewriteRule ^(.*)$ example/$1 [L]

Lets break that down.

  • RewriteCond %{REQUEST_URI} !^/example/
    • Example should be the folder that you want to rewrite to.  Not having this causes a loop
  • RewriteCond %{HTTP_HOST} ^(www\.)?example_domain
    • Examplle_domain is your real domain, without the end TLD (.com, .net, .whatever)
    • This isn't needed per say, but if you have multiple domains going to different directories, it helps.
  • RewriteRule ^(.*)$ example/$1 [L]
    • Again, this is the folder that you want to rewrite to. 
  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

How to create a .htaccess file

Creating a .htaccess is easier then it sounds. You can create an .htaccess file in any text...

http Error codes

The following are http status and error codes that are returned for each file access via a web...

Frontpage Publishing via FTP

Frontpage extensions are not supported on our servers due to bugs in the extensions (some...

How to upload / create your site.

Creating your site How you create your site depends on what you want to do with it.  You...

Changing php.ini directives via .htaccess

A script you want to use requires a different setting then we have set?  No problem, you...