Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts

Thursday, September 27, 2012

Redirect all pages to new domain


This code in .htaccess does redirect all requests to a new domain:

RewriteEngine On
RewriteRule ^(.*)$ http://WWW.NEW-DOMAIN.COM/ [R=301]

The problem was, all other directives work like: 

www.old-domain.com/bla -> www.new-domain.com/bla

but I need


www.old-domain.com/bla -> www.new-domain.com

www.old-domain.com/more/bla -> www.new-domain.com

So the htaccess code above works fine.




Thursday, September 20, 2012

htaccess non-www and www http to https


RewriteEngine on

RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

<Files .htaccess>
order allow,deny
deny from all
</Files>

Wednesday, September 19, 2012

htaccess non-www to www


RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

<Files .htaccess>
order allow,deny
deny from all
</Files>