Jump to content

htaccess redirect help


bestrong

Recommended Posts

Hello,

 

I have a website where I need to:

 

redirect all http requests to https  and remove the www from all requests.

 

For example

 

http://mysite.com -> https://mysite.com

http://www.mysite.com -> https://mysite.com

http://www.mysite.com/accounts -> https://mysite.com/accounts

www.mysite.com -> https://mysite.com

https://www.mysite.com -> https://mysite.com

 

 

is there any way of doing this? I tried and tried in .htaccess with url rewriting ... but I got all sorts of unexpected results.

 

please help

 

thanks

 

Link to comment
https://forums.phpfreaks.com/topic/191402-htaccess-redirect-help/
Share on other sites

First we do the www url, NC = case insenitive  OR = or

So we are first removing a www and if it is true we drop to the rewrite rule, if false the next condition. The second rewrite rule does the domain sans www and drops to the rewrite rule.

 

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC,OR]

RewriteCond %{HTTP_HOST} domain.com$ [NC]

RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]

 

 

HTH

Teamatomic

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.