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 upload / create your site.

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

Aliasing Domains with Proper SEO (domains and Search Engines)

Aliasing a domain to a primary domain is a great way to simplify domain hosting as only one main...

Your own php error.log and displaying errors

Is your script not behaving as expected or producing a white page?   If so, it could be a PHP...

Changing php.ini directives via .htaccess

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

openssl 1.0.1 or greater in PHP -- hsphere only

If you receive an error with your php script about "openssl 1.0.1 or greater" is required, please...