Forum Moderators: phranque

Message Too Old, No Replies

302 hijack and .htaccess File Fix

302 hijack .htaccess

         

hilley

2:21 am on Feb 22, 2006 (gmt 0)

10+ Year Member



I have encountered a 302 hijack and am taking steps to resolve the issue. First step is to include a base href tag in every site on server. Second and final step is to insert the following in my root ".htaccess" file:

RewriteCond %{HTTP_HOST}!^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Or, for www-to-non-www redirection, use this syntax:

RewriteCond %{HTTP_HOST}!^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]

There is only one problem with this ... I have never done this before! Somebody please help me!

What is a .htaccess file? Do I create this in notepad and save as a .htaccess file ... then upload to the root folder through dreamweaver where I would normally put my .index file?

Any help WILL help ... Looking forward to the comments!

jdMorgan

3:22 am on Feb 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hilley,

Welcome to WebmasterWorld!

I don't know anything about uploading with dreamweaver, but generally, yes, you would upload a plain-text file named ".htaccess" to the same directory where your home page and robots.txt file reside.

Note that on all servers, you'll need to preface whichever of those two code snippets you choose with the line:


RewriteEngine on

and on many servers, you may need to add

Options +FollowSymLinks

ahead of that line, too.

---

Full example:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Using mod_rewrite is fairly powerful voodoo, and you may want to study it a bit; I really can't recommend that anyone put any code on their server that they don't understand completely. To that end, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

hilley

5:45 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



jdmorgan,

thanks for the information ... I am gonna give it a try ;-)