Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect https and http in .htaccess

I have an old url (test.me.com) and I would like to redirect it to www.me.com.

So I added this line to my .htaccess file:

RewriteRule ^(.*)$ http://www\.me\.com/$1 [L,R=301]

But as it turns out, Google has already indexed some of the pages. And since I have an SSL Certificate, the full url is https://test.me.com. So the redirect of above won't affect the https files...

I've tried this one, but with no luck.

RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http]

# redirect urls with index.html to folder
RewriteCond %{HTTP_HOST} ^test.me.com [NC]
RewriteRule ^.*$ %{ENV:ps}://www.me.com/%1 [R=302,L]

How can I configure my .htaccess file that both http://test.me.com and https://www.test.com are redirected to http://www.me.com?

like image 750
Michiel Avatar asked Aug 04 '26 02:08

Michiel


1 Answers

# redirect https requests or request on test.me.com to http://www.me.com
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{HTTP_HOST} ^test\.me\.com$ [NC]
RewriteRule ^(.*)$ http://www.me.com/$1 [R=301,L]

or alternatively to also redirect me.com to www.me.com

RewriteCond %{HTTPS} =on [OR]
RewriteCond %{HTTP_HOST} !^www\.me\.com$ [NC]
RewriteRule ^(.*)$ http://www.me.com/$1 [R=301,L]
like image 155
Gerben Avatar answered Aug 05 '26 19:08

Gerben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!