1 Star2 Stars3 Stars4 Stars5 Stars (15 votes, average: 5.00 out of 5)

htaccess redirect to no www include ssl

htaccess redirect to no www include ssl

So there are sometimes when we need to htaccess redirect our site to an ssl and remove the www part of it. Here is a code to help webmasters do that. What you need to do is look for the file called .htaccess. It will be in the root folder of your site. It is invisible to everyone that does not have access to the root file of your site.  For rewrite rules such as this one you have to make sure that you start the code out with RewriteEngine On. This tells the server that we will be rewriting urls for our guests. You can use the htaccess rewrite rule on any apache server running Linux. There are several different types of rewrite rules that you can apply to a website using the htaccess rewrite rules. This is also a good way to make your site SEO friendly to the search engines and will help you get away from SSL errors when a web surfer puts the www in front of the url when it is not used.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

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

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

If you just want to get rid of the www use the code below in your htaccess file.

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

If you want to add the www use the code below

RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com$ RewriteRule (.*) http://www.example.com$1 [R=301]

This code can only be used on an Apache server.

Subscribe To My YouTube Channel:
Enter your email address:Delivered by FeedBurner
htaccess redirect to no www include ssl was last modified: May 11th, 2015 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips


Cool People Share:
htaccess redirect

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.