redirect in htaccess code example

Example 1: https redirect htaccess

RewriteEngine On 
RewriteCond %{HTTPS} !on 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Example 2: htaccess redirect to html page

RedirectMatch 301 ^/blog/about /blog/about.html

Example 3: https and www htaccess redirecr

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Example 4: htacces redirect

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.vecchiodominio\.com$
RewriteRule (.*) http://www.nuovodominio.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^vecchiodominio\.com$
RewriteRule (.*) http://www.nuovodominio.com/$1 [R=301,L]

Tags:

Php Example