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

Which PHP versions do you support on shared hosting?

We currently support the following PHP versions on our shared hosting servers: 5.6 7.1 7.2...

PHP settings and the .user.ini file

Most settings for PHP can be configured via a file called ".user.ini" as defined by the...

Force https via htaccess

RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

How to create a .htaccess file

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

Block HTTP request based on user agent - browser used

If you need to block a user agent / bot / browser from your site, you can do so with a .htaccess...