Site Redirect

liunx

Guest
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 <b>example.com</b> to get redirected to <b>www.example.com</b>. 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.<br /><br />I'm using phpNuke if that matters. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><br /><br />Thanks.<br /><br /><img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
I might not understand your question correctly so I better ask. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/unsure.gif" style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> <br />Are example.com and <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w --> the same site?<br />If so, anyone typing example.com will end up at your <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w --> by default. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Robert all your web site files are in your public_html folder<br />the www folder is a shortcut to the public_html folder<br /><br />your .htaccess file is normally a hidden file and also in the public_html folder.<br />You can see it in cpanels file manager or an ftp program if you enable viewing hidden files.<br /><br />If typing in domain.ext does not goto your web sites public folder<br />but <!-- w --><a class="postlink" href="http://www.domain.ext">www.domain.ext</a><!-- w --> does<br />please open a help desk ticket to customer support and they get it working for you.<!--content-->
Thomas: Yes, it's the same site.<br /><br />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"<br /><br />Thanks <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /><!--content-->
I may have done it wrong but last time I tried to do that the mysite redirected to <!-- w --><a class="postlink" href="http://www.mysite">www.mysite</a><!-- w --> 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.<!--content-->
I'm trying to do the opposite of what you're doing--I want <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w --> to redirect to example.com. This code works for me:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]<br />RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]<!--c2--></div><!--ec2--><br /><br />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 .)<br /><br />Then you'll need to reverse the above code, which I think would look like:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^\.example\.com$ [NC]<br />RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]<!--c2--></div><!--ec2--><br /><br />Open your new .htaccess file and paste the above in the file, and it should work for you.<br /><br />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. <br /><br />But if you don't have any other redirects going on, then this should be ok.<!--content-->
thanks for the help everyone. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br /><br />owatagal: tried your suggestion, and it didn't work. (I did change the "yoursite" info too <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/laugh.gif" style="vertical-align:middle" emoid=":lol:" border="0" alt="laugh.gif" /> )<br /><br />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.<br /><br />thanks again!<!--content-->
eureka! it did work! what I had to do was change:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^\.example\.com$ [NC]<br />RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]<!--c2--></div><!--ec2--><br /><br />to this:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^\example\.com$ [NC]<br />RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]<!--c2--></div><!--ec2--><br /><br /><i>very</i> slight change, just took the . out of the second line before "example" since there would be no period before that.<br /><br />works great!!<br /><br /> <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/clapping.gif" style="vertical-align:middle" emoid=":clapping:" border="0" alt="clapping.gif" /> <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/kicking.gif" style="vertical-align:middle" emoid=":dance:" border="0" alt="kicking.gif" /><!--content-->
You could probably drop off that first backslash too, then, because it was escaping the period in the original bit of code. <br /><br />Pesky periods... glad it worked, though!<!--content-->
Great job guys!<br />Way to stick with it Robert! Thanks to owatagal too! Now I have a new tool in my box as well. Thanks!<!--content-->
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 <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w --> not example.com. I tried the rewrite rules but they did not work for me. Doesnt anyone elese have an idea?<!--content-->
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 <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w -->) or does the rewrite work but the login doesn't?<!--content-->
I have tried both <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^\example\.com$ [NC]<br />RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]<!--c2--></div><!--ec2--><br />and<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^\.example\.com$ [NC]<br />RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]<!--c2--></div><!--ec2--><br />I have no other rewrite rules in my .htaccess file. and yes the <!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->rewrite rule itself [does]not working (i.e. the site doesn't direct to <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w -->)<!--QuoteEnd--></div><!--QuoteEEnd--><!--content-->
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:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^example\.com$ [NC]<br />RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]<!--c2--></div><!--ec2--><br /><br />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.<!--content-->
Thanks owatagal problem solved. you rock! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/clapping.gif" style="vertical-align:middle" emoid=":clapping:" border="0" alt="clapping.gif" /><!--content-->
 
Back
Top