Mohan K
Mohan K

Reputation: 161

redirect https to http for domain.com page only by using htaccess

I have purchased SSL certificate. And i have added https to all my web page using below script in htaccess file.

RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301,NC]

Here i need to redirect from https to http for my homepage only.

Example:

https://www.domain.com to http://www.domian.com

Other pages should be redirect like below.

http://domain.com/login to https://www.domain.com/login

http://www.domian.com/register to https://www.domian.com/register

Note: I need to append www to all my URLs for SEO purpose.

Thanks in advance.

Upvotes: 1

Views: 137

Answers (1)

anubhava
anubhava

Reputation: 785286

You can use .+ to not to match landing page in your regex:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.+)$ https://www.domain.com/$1 [L,R=301,NE]

However since you're also adding www I suggest following rules:

RewriteEngine On

# all pages except home page
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(?!frontpageajax).+$ https://www.%1%{REQUEST_URI} [L,NC,R=301,NE]

# landing page redirect https=>http
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(frontpageajax/?)?$ http://www.%1 [L,NC,R=301]

Upvotes: 1

Related Questions