I have an issue on my website, where all http URLs redirect to the https of the homepage. For example,

http://example.com/ppc-services/ redirects to https://example.com/

I have added this to .htaccess but didn't work

# Redirect to HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

I had also tried the following, but no luck:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Could someone help me?

  • The second code should work. Did you check if mod_rewrite is enabled on your server?
    – gael
    Dec 21, 2019 at 10:56
  • 1
    Do you have any other code in your htaccess file or Apache conf files? If so, please post it. These rules look fine. They wouldn't be redirecting to the home page. It must be some other rule getting in the way. Dec 21, 2019 at 11:35
  • "The second code should work." - So should the first. It also depends on where the directives are placed and what other directives you might have. However, you should ideally find where this "incorrect" redirect is occurring in your code and fix that.
    – MrWhite
    Dec 23, 2019 at 2:03


Browse other questions tagged or ask your own question.