Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Redirect HTTP to HTTPS, URL structure option 1, no customized htaccess file

+6 votes
522 views
asked Mar 21, 2017 in Q2A Core by Martu
How to redirect HTTP to HTTPS when using default (URL Structure option 1 chosen) htaccess file?

URL structure:
/123/why-do-birds-sing (requires htaccess file) 

My .htaccess file:

Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>


Q2A version: 1.7.4

2 Answers

+3 votes
answered Mar 22, 2017 by Dr-Hack
selected Mar 27, 2017 by Martu
 
Best answer

Add the following :

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://blog.drhack.net/$1 [R,L]
Just above </IfModule>
that should redirect all your http requests to https .. and change the website address to your website
commented Mar 22, 2017 by Dr-Hack
i dont know whats wrong with formatting here :/ it was fine before ..
+3 votes
answered Apr 27, 2017 by vivian

Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.YOURDOMAIN.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.YOURDOMAIN.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>

This one will redirect to https://www with showing 404 page correctly. 

By simply adding the below code Your 404 page will not be shown.

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.YOURDOMAIN.com/$1 [R=301,L]

So use the above one.

Correct me if you have any better suggestions. I would like to know how pokemondb.net is using the htaccess file. it may be better than this.

...