Shilpa
Shilpa

Reputation: 21

Http to Https redirection issue?

# Redirect HTTP to HTTPS 
RewriteCond %{HTTPS} !=on RewriteRule (.*) 
https://%{SERVER_NAME}/$1 [R,L]
# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L]   
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L] 
</IfModule>
# END WordPress

This is my websites htaccess code. I want to redirect my site http to https.I tried some code but not working

Upvotes: 1

Views: 55

Answers (1)

Ankur Singh
Ankur Singh

Reputation: 157

Use the following code if your site in root of the server.

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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

OR assuming from your code its in /blog/ folder. Using the following code instead.

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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

Upvotes: 2

Related Questions