Skip to content

How to use Apache mod_rewrite

Updated 1 min read

Updated: 28 September 2026 · Applies to: Apache 2.4 (.htaccess)

Apache's mod_rewrite changes or redirects URLs with rules in your .htaccess file. It is enabled on our servers; start your rules with RewriteEngine On.

Common examples

Redirect all traffic to HTTPS:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect one old page to a new one:

RewriteRule ^old-page\.html$ /new-page/ [L,R=301]

Send every request that is not a real file or folder to index.php (used by WordPress, Laravel and most PHP frameworks):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Note: A syntax error in .htaccess causes a 500 Internal Server Error. Keep a copy of the working file before you edit it. Apache's mod_rewrite documentation (httpd.apache.org, version 2.4) explains every flag.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Managed cPanel VPS

cPanel included; we handle updates, security and monitoring.

Server management

on-demand administration, hardening, migrations and monitoring.

Was this answer helpful?

Still stuck? Open a ticket