Nexcess Logo

Example code for common .htaccess rewrite commands

Knowledge Base Home

Notice anything different?

We've enhanced the appearance of our portal and we're working on updating screenshots. Things might look different, but the functionality remains the same.
September 10, 2019

Common .htaccess rewrite commands

Attention: Do not attempt to edit your .htaccess file if you have no previous experience, or you can significantly degrade your site.

Force SSL for the entire site or directory

RewriteEngine On                                     
RewriteCond %{HTTPS} off                             
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}  

Rewrite base directory into a sub-directory

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] 
RewriteRule ^$ http://%{HTTP_HOST}/subfolder/index.php [R,L]

Route requests through PHP-based dispatcher

RewriteEngine On 
RewriteBase / 
RewriteCond %{REQUEST_URI} !^/dispatcher.php 
RewriteRule (.*) /dispatcher.php%{REQUEST_URI} [L]
Jason Dobry
We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.