Hi Developer,
This tutorial will show you how to redirect your non-www URLs to www, or vice-versa, using htaccess. Let’s get started.
Web development has a lot of nuances that are learned along the way. One of those is that www and non-www URLs are technically different and that it could hurt your SEO if you keep both around.
For example, the domains https://www.opencodesolution.com and https://opencodesolution.com (note the “www” in one but not the other) are technically different. However, if you click on either, they’ll redirect to the same place, which is a good thing. It helps Google and other search engines to only index one and to not split results.
Most users reading this article will likely be on an Apache server. Here are the steps you’ll need.
Use your host’s file manager or an FTP program to access your .htaccess file. Note that it has a dot preceding it.
If you don’t find, check to see if there’s a htaccess.txt file, which can be renamed to .htaccess if it came with your CMS (edit the file and check its contents to be sure). If there isn’t a htaccess.txt file either, create a new file called .htaccess.
Then insert either of the following lines and modify the code with your domain:
I would use this rule:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Congratulations, you have successfully forced www or non-www! Now when you type in your domain name with either www in front or not, it should display as you have set it in the .htaccess
file
Hope it can help you…
Categories : Laravel
Tags : .htaccess