i just want to redirect my domain. actually my website is working so there is no problem but i just want that when someone enter the website without (www) PHP has to detect this and redirect to with (www) i hope you understand. Thank you in advance. I am sorry for my bad English by the way.
Asked
Active
Viewed 41 times
0
-
Are you using nginx or apache or something else please be specified – teck wei Dec 19 '16 at 21:10
-
This is normally done by editing/creating a .htaccess file and putting a mod-rewrite rule in it.. That might look like this... RewriteCond %{HTTP_HOST} ^superdupersite\.com(.*) RewriteRule (.*) http://www.superdupersite.com/$1 [R=301,L] – Duane Lortie Dec 19 '16 at 22:07
-
Possible duplicate of [Redirect non-www to www in .htaccess](http://stackoverflow.com/questions/12050590/redirect-non-www-to-www-in-htaccess) – random_user_name Dec 19 '16 at 22:26
2 Answers
1
only because I can't paste this as a comment.. redirect non-www to WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^superdupersite\.com(.*)
RewriteRule (.*) http://www.superdupersite.com/$1 [R=301,L]

Duane Lortie
- 1,285
- 1
- 12
- 16
-
Please don't answer questions like this that have been [asked and answered](http://stackoverflow.com/questions/12050590/redirect-non-www-to-www-in-htaccess) - instead, vote to close as duplicate. – random_user_name Dec 19 '16 at 22:27
0
This can be done using your hostings DNS records settings. If you are using a Linux based hosting you can also do it using a htaccess document. Inside your HTAccess document simply put:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.your-domain\.com
RewriteRule (.*) http://your-domain.com/$1 [R=301,L]
Read more about this: https://www.chriswiegman.com/2011/09/how-to-properly-redirect-your-domain-with-or-without-www/

James McNee
- 302
- 2
- 14
-
-
Also, please don't answer questions like this that have been [asked and answered](http://stackoverflow.com/questions/12050590/redirect-non-www-to-www-in-htaccess) - instead, vote to close as duplicate. – random_user_name Dec 19 '16 at 22:26