mrkablooey Posted February 28, 2005 Posted February 28, 2005 I tried using the redirect in cpanel but got an error when trying to go to my site so I removed the redirect. I'd like someone typing example.com to get redirected to www.example.com. I've read about using .htaccess but don't have any files in my root directory... they all reside in my public_html/www directory. I'm using phpNuke if that matters. Thanks. Quote
TCH-Thomas Posted February 28, 2005 Posted February 28, 2005 I might not understand your question correctly so I better ask. Are example.com and www.example.com the same site? If so, anyone typing example.com will end up at your www.example.com by default. Quote
TCH-Don Posted February 28, 2005 Posted February 28, 2005 Robert all your web site files are in your public_html folder the www folder is a shortcut to the public_html folder your .htaccess file is normally a hidden file and also in the public_html folder. You can see it in cpanels file manager or an ftp program if you enable viewing hidden files. If typing in domain.ext does not goto your web sites public folder but www.domain.ext does please open a help desk ticket to customer support and they get it working for you. Quote
mrkablooey Posted February 28, 2005 Author Posted February 28, 2005 Thomas: Yes, it's the same site. Thomas/Don: It's a nuke site with login. If I type "www.example.com" into my browser window, it logs me in. If I go to "example.com" only, it does not. It displays the site fine but I get the login window, and my address bar says "example.com". I've been to sites that if you type "example.com", it automatically changes (in the address bar) to "www.example.com" Thanks Quote
Deverill Posted March 1, 2005 Posted March 1, 2005 I may have done it wrong but last time I tried to do that the mysite redirected to www.mysite which is the same place so it tried to redirect and got very confused and spewed an error at me. Since both are the same directory and files I don't think it can happen. The other sites probably don't have a www symlink so they can do that. Hang tight and someone who can confirm or deny that which I said will be along and hopefully they will know a solution. Quote
owatagal Posted March 1, 2005 Posted March 1, 2005 I'm trying to do the opposite of what you're doing--I want www.example.com to redirect to example.com. This code works for me: >RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] I have it in an .htaccess file at my site root. Instead of going through CPanel's redirect option, open the File Manager, navigate to /public_html/, and if you don't already have an .htaccess file create one (use the create new file link, then just call it .htaccess with nothing in front of the .) Then you'll need to reverse the above code, which I think would look like: >RewriteEngine on RewriteCond %{HTTP_HOST} ^\.example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] Open your new .htaccess file and paste the above in the file, and it should work for you. A word of warning--if you already have a lot of redirects going on, this may not work. I know of at least one folder on my site that is having problems with this redirect clashing with another, and the server has decided to just send me back to the home page instead of to the page I expect. But if you don't have any other redirects going on, then this should be ok. Quote
mrkablooey Posted March 1, 2005 Author Posted March 1, 2005 thanks for the help everyone. owatagal: tried your suggestion, and it didn't work. (I did change the "yoursite" info too ) it's not too big of a deal, just "one of those things" I'd like to fix. i'll try any other suggestions people may have. thanks again! Quote
mrkablooey Posted March 1, 2005 Author Posted March 1, 2005 eureka! it did work! what I had to do was change: >RewriteEngine on RewriteCond %{HTTP_HOST} ^\.example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] to this: >RewriteEngine on RewriteCond %{HTTP_HOST} ^\example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] very slight change, just took the . out of the second line before "example" since there would be no period before that. works great!! Quote
owatagal Posted March 1, 2005 Posted March 1, 2005 You could probably drop off that first backslash too, then, because it was escaping the period in the original bit of code. Pesky periods... glad it worked, though! Quote
Deverill Posted March 1, 2005 Posted March 1, 2005 Great job guys! Way to stick with it Robert! Thanks to owatagal too! Now I have a new tool in my box as well. Thanks! Quote
thejerm Posted March 24, 2005 Posted March 24, 2005 I am having the same problem the first person is having. Some parts of my site require a password and the url needs to be www.example.com not example.com. I tried the rewrite rules but they did not work for me. Doesnt anyone elese have an idea? Quote
owatagal Posted March 24, 2005 Posted March 24, 2005 Which version of the rewrites rules in this post did you try? And do you have other rewrite rules in your .htaccess that might interfere with this? And is the rewrite rule itself not working (i.e. the site doesn't direct to www.example.com) or does the rewrite work but the login doesn't? Quote
thejerm Posted March 24, 2005 Posted March 24, 2005 I have tried both >RewriteEngine on RewriteCond %{HTTP_HOST} ^\example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] and >RewriteEngine on RewriteCond %{HTTP_HOST} ^\.example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] I have no other rewrite rules in my .htaccess file. and yes the rewrite rule itself [does]not working (i.e. the site doesn't direct to www.example.com) Quote
owatagal Posted March 25, 2005 Posted March 25, 2005 I think the problem is in the backslashes--since the code is adapted from something where I was doing the reverse (stripping the www off the URL), the first backslash in the second line was there only to escape the period. See what happens if you take that backslash (and period) out: >RewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] I tried this on a site that doesn't have any other redirects, and it worked ok. I hope it fixes the problem for you. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.