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
When you visit our site, we may collect personal information about you, including through cookies and similar technology. To read more, please refer to our Privacy Policy. By clicking accept or continuing to browse, you consent to our practices.