- This topic is empty.
-
AuthorPosts
-
June 13, 2005 at 3:47 pm #588916AnonymousInactive
We’ve discussed the perils of using the www and non-www versions of your domain here before, but I’ve never considered the possibility of malicious webmasters using it to sabotage your site.
An article today at Threadwatch points out how to redirect your non-www domain to the regular www version and insure that you’re safe.
http://www.threadwatch.org/node/2817
However, the mod_rewrite hacks there seem to add an extra slash in the redirect. Here’s a better version from the Apache URL Rewriting Guide:
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L]
June 15, 2005 at 10:01 am #667132AnonymousGuestthanks Ken,
for us real challenged, can you explain where that code should be inserted?
for example, should it go on our index page? all pages?
and does it go in the head section? (I assume).
please add any other info I need to know and probably don’t.
thanks again
S.
June 15, 2005 at 11:13 am #667137AnonymousInactiveGo to your hosting CP – Website Settings – Custom Settings (Apache Config), or if you have acces to your .htaccess – just add this commands.
June 15, 2005 at 6:38 pm #667159AnonymousInactiveI realized when I posted this that I wasn’t giving all the information really necessary. The reason was that I knew the way I installed it on my system would be different from virtually everyone else, and I wasn’t sure about how to install it for everyone else.
(I run Plesk on my server, so I installed this in /home/httpd/vhosts/domain.com/conf/vhost.conf, and then had to run
/usr/local/psa/admin/sbin/websrvmng –reconfigure-vhost –vhost-name=)
But that’s only if you are running Plesk (a hosting control panel).vd752’s description of where to put it looks fine to me. For the htaccess solution, I believe the file must be named ‘.htaccess’ and placed in the root directory where your content resides. Someone please correct me if I’m wrong. I’m sure you can find more detailed instructions by Googling htaccess.
You’ll probably have to restart Apache afterwards for this to take effect.
June 15, 2005 at 9:10 pm #667161AnonymousInactiveI think the coding above is incorrect. I think it’s redirecting from http://www.example.com to http://www.example.com. Someone double-check please? (It should, unless I misunderstand, redirect from http://example.com to http://www.example.com.)
June 15, 2005 at 10:32 pm #667166AnonymousInactiveYes there is an error in that code.
This is what i have in my .htaccess file and it works fine.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]June 15, 2005 at 10:50 pm #667167AnonymousInactiveBoth my example and cyclone’s will work.
In my example, note the exclamation mark in the RewriteCond lines.
The line RewriteCond %{HTTP_HOST} !^http://www.domain.com [NC]
means match anything that does NOT start with http://www.domain.comJune 15, 2005 at 11:42 pm #667169AnonymousInactiveYours worked for me, Ken.
Thanks!!!
June 16, 2005 at 12:33 am #667170AnonymousInactiveVery cool to know. Thanks.
BlackjackInfo wrote:Both my example and cyclone’s will work.
In my example, note the exclamation mark in the RewriteCond lines.
The line RewriteCond %{HTTP_HOST} !^http://www.domain.com [NC]
means match anything that does NOT start with http://www.domain.comJune 16, 2005 at 2:30 am #667173AnonymousInactiveI guess there wasn’t an error then, i didnt know about exclamation mark.
June 16, 2005 at 1:56 pm #667183AnonymousInactiveHi,
one quick question. Currently trying to install the code, but having some problems. Which parts of the code need to be edited?
RewriteEngine on
RewriteCond %{HTTP_HOST} !^http://www.domain.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L]
Only the domain name, or also anything else? Can I place this code anywhere in the .htaccess file, or does it have to be in a specific spot?
I’m still very new to this stuff!Thanks for your help,
burgi
June 16, 2005 at 2:45 pm #667187AnonymousInactiveOk, I got it to work, but I used cyclone’s code because I was not able to get the other code to work (probably too stupid to get it done). lol
Thanks,
burgi
June 16, 2005 at 3:59 pm #667191AnonymousInactiveburgi82 wrote:Ok, I got it to work, but I used cyclone’s code because I was not able to get the other code to work (probably too stupid to get it done). lolThanks,
burgi
Same here.
June 21, 2005 at 8:15 pm #667335AnonymousInactiveHi all,
I’ve been messing around with this .htaccess trick for about an hour now, and I can’t seem to get anything to happen. I tried the examples from both Ken and cyclone.
I go into my Control Panel, and then I go to the Website Files and Scripts section where I can edit the .htaccess file. I have two options: Add Rule, or Edit Manually. I selected Edit Manually so I could just copy and paste the code into the text box.
I pasted the code, changed the dummy URLs to my own URL, and then saved the file.
Now when I go and type my url in the address bar without the www, I expect it to redirect to the www version, but it doesn’t. Isn’t that what it’s supposed to do?
Any ideas on what I’m doing wrong here? Do I need to stop and restart the server or something?
Here are the exact two methods I tried:
[HTML]
[/HTML][HTML]RewriteEngine On
RewriteEngine on
RewriteCond %{HTTP_HOST} !^onlinepokercraze.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.onlinepokercraze.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^onlinepokercraze.com$ [NC]
RewriteRule ^(.*)$ http://www.onlinepokercraze.com/$1 [R=301,L][/HTML]Thanks guys.June 21, 2005 at 10:01 pm #667337AnonymousInactiveYes, you’ll need to restart Apache for the change to take effect.
Hope that works for you. -
AuthorPosts