0

What to write in htaccess

I want to redirect the different URL to one main URL.

Thanks in advance.

Avijit
  • 3,834
  • 4
  • 33
  • 45
  • WRT duplicate closing: Other question is only a half duplicate. OP needs a RewriteCond to handle his various domains/protocols. – CrazyCasta Jan 15 '14 at 11:22
  • Regardless of duplicate closing, you need to clarify your question. Do you know anything about the apache redirect module? If not, you need to go read up on it, if you do please tell us what you've tried so we can more specifically help you. – CrazyCasta Jan 15 '14 at 11:24

2 Answers2

0

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [L,NE,R=302]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

1) Redirect domain.com to www.domain.com:

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

2) http to https

RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Redirect based on port number

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Damodaran
  • 10,882
  • 10
  • 60
  • 81