PowerQA is a state of the art discussion software that makes online discussions fun. It's simple, fast, and powerful.
0 votes

How i add auto redirect http for https

Hi all. How i auto redirect my site http for https.

Today i add my site https protocol.

Site open adress and How i auto redirect my site url for

My site htaccess file.

DirectoryIndex index.php 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} robots.txt$ [NC] 
RewriteRule ^([^/]+) $1 [L] 
RewriteCond %{HTTP_HOST} ^\.com 
RewriteRule ^(.*)$$1 [R=301,L] 
#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] 

i add after RewriteEngine On code

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

But this code dont work.

by yerbol89 asked Aug 29, 2015 in Core

Please log in or register to add a comment.

Please log in or register to answer this question.

2 Answers

+2 votes
Put the below code in 
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Or add the following code 

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?your domain name\.com$ [NC]
RewriteRule ^$ https://www.your domain{REQUEST_URI} [R,L]

The above code is good but not the best.
Apache docs does not recommend using rewrite to direct users.

use this instead

To redirect http URLs to https, do the following:

<VirtualHost *:80>
    Redirect /
</VirtualHost >

<VirtualHost *:443>
    # ... SSL configuration goes here
</VirtualHost >
by Vanbells answered Aug 29, 2015
by Vanbells edited Aug 29, 2015

1 Comment

I found my problem. I use my site Nginx+Apache and this you code dont work my server.

When using Nginx + Apache bundles will result in an error of the cyclic forward. Therefore, the redirect will need to configure it in Nginx:

Please log in or register to add a comment.

0 votes

301 redirect from http to https

Nginx you need to create two server section in the configuration file, one for http (port 80), one for https (port 443).
For the new domain conf. file nginx
Section server, to open at http (port 80) and forwarding settings:

server {
    listen IP server: 80;
    rewrite ^ https: //$request_uri? permanent;

Section server, to open at https (port 443), where the main domain settings.

server {
    listen IP server: 443;

For existing domain Conf. File nginx
If you make changes to an existing section of the conf. File nginx do this: From the main section of the domain, remove the string of the form

listen IP server: 80;

And create a new server section like this:

server {
    listen IP server: 80;
    rewrite ^ https: //$request_uri? permanent;

After making changes to the configuration file Nginx, for entry into force of these changes, you need to restart it like this:

service nginx restart

The trick is that I can not do it. :)

My ngnix.conf file:

user www-data;
worker_processes auto;
error_log  /var/log/nginx/error.log;
pid        /var/run/;

events {
    worker_connections  1024;
    # multi_accept on;

http {
    include       /etc/nginx/mime.types;

    access_log    /var/log/nginx/access.log;

    sendfile        on;
    tcp_nopush      on;

    keepalive_timeout  30;
    keepalive_requests 400;
    reset_timedout_connection on;
    tcp_nodelay        on;
    server_tokens off;

    ssl_prefer_server_ciphers On;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    client_max_body_size 8m;
    client_body_buffer_size 4m;

    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 300;
    proxy_buffer_size 64k;
    proxy_buffers 8 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 10m;

    gzip  on;
    gzip_comp_level     8; 
    gzip_vary on;
    gzip_static off;
    gzip_types text/css text/plain application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
    gzip_min_length  1024;
    gzip_disable     "msie6";
    gzip_proxied     any;

    include /etc/nginx/conf.d/default_server.conf;

    server_names_hash_bucket_size 128;
    log_format isp '$bytes_sent $request_length';
    include /usr/local/ispmgr/etc/nginx.domain;
    server {
        listen ssl;
        disable_symlinks if_not_owner from=$root_path/$subdomain;
        set $root_path /var/www/szh/data/www/;
        set $subdomain "";
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
            access_log off;
            access_log /var/www/nginx-logs/szh isp;
            expires 30d;
            root $root_path/$subdomain;
            error_page 404 = @fallback;
        location / {
            proxy_redirect /;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Real-IP $remote_addr;
        location @fallback {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Real-IP $remote_addr;
        include /usr/local/ispmgr/etc/;
        if ($host ~* ^((.*)$) {
            set $subdomain ../$1;
        index index.php;
        ssl_certificate /var/www/httpd-cert/szh/;
        ssl_certificate_key /var/www/httpd-cert/szh/;

by yerbol89 answered Aug 30, 2015

1 Comment

so  is it finally fixed? or you haven't still fixed it yet?

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.


  • 338 questions
  • 276 answers
  • 100 users

Post types