Panel
Newbie
islamafify
0 votes
QA 42 views

What is the code you write in .htaccess file

What is the code you write in .htaccess file

To redirect all visitors to https://www.question-answer.org
by islamafify asked Dec 29, 2015 in Others

Please log in or register to add a comment.

Please log in or register to answer this question.

1 Answer

Expert
Vanbells
+2 votes
RewriteEngine On

#redirect non www to www  first

RewriteCond %{HTTP_HOST} !^www\.

RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#now redirect to https

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Note this will redirect using the 301 'permanently moved' redirect, which will help transfer your SEO rankings.

To redirect using the 302 'temporarily moved' change [R=302,L]
by Vanbells answered Dec 29, 2015
by Vanbells edited Dec 30, 2015

4 Comments

If you have an existing .htaccess file:

Do not duplicate RewriteEngine On.
Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On
Ok thanks
But this code does redirect to https://or https://www
I want each visitor is redirected to https://www only
I have edited the answer to only redirect to https://www
Please check if it works for you
Thanks too you
It has helped me solve the problem

Please log in or register to add a comment.

Welcome to PowerQA. PowerQA is a new discussion software (not OSS). Here is a community for PowerQA developers. Current stable version is V1.9.4. It is enhanced day by day.

User ranking (month)

More ...

Statistics

  • 337 questions
  • 276 answers
  • 480 comments
  • 97 users

Post types

...