php - HTTP to HTTPS Redirection Issue


I want to redirect http requests to https node.

I tried,

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Please find below few test results, I executed, redirected to

// Worked as expected not redirected to

//Didn't work as expected

EDIT: This is my.htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews

    #Options +FollowSymLinks
    RewriteEngine On

    RewriteRule ^(api-docs|docs)($|/) - [L] # HERE IS THE PROBLEM I THINK

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # redirect all http -> https
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


Please let me know how to achieve or fix this.




I use with success the following rule, note the difference of the regex pattern

RewriteRule ^(.*)$ https://domainname/$1 [R,L]



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

Apache Wiki

People are also looking for solutions to the problem: linux - No stdout when php process is spawned in the background


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.