.htaccess mod_rewrite snippets

Redirect all parked domains onto main domain with https

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.domain\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^http://www\.domain\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} !^www\.domain\.co\.uk$ [OR]
RewriteRule ^(.*)$ https://www.domain.co.uk/$1 [R=301,L]

Redirect all parked domains onto main domain

# Force all traffic onto one domain with www (will redirect all aliases)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301]

Exclude a folder from rewrite rules

RewriteCond %{REQUEST_URI} !^/(foldername|foldername/.*)$

Example from WordPress rewrite rules:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(foldername|foldername/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Revisions

There are no revisions for this post.

Tags: , , ,

No comments yet.

Leave a Reply