Example code for common .htaccess rewrite commands

    October 3, 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]

    Was this article helpful?

    Send feedback

    Can’t find what you’re looking for?

    Our award-winning customer care team is here for you.

    Contact Support