Forum Moderators: phranque

Message Too Old, No Replies

301 redirect

proper syntax

         

yowza

11:22 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



I am trying to make sure that users do not access my site through the ip address, only through the web address.

Is this how it's done?

ErrorDocument 400 /notfound.htm
ErrorDocument 403 /notfound.htm
ErrorDocument 404 /notfound.htm
ErrorDocument 500 /notfound.htm
ErrorDocument 501 /notfound.htm

Redirect 301 33.22.323.232/ [widgets.com...]

Birdman

12:26 am on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks okay, have you tried it? All you need to do is update your htaccess with the redirect and then use the server headers utility [webmasterworld.com] on WW to see if you get a 301 header returned.

jdMorgan

12:51 am on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using mod_rewrite:

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

-or-

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

Jim

yowza

1:44 am on Nov 27, 2003 (gmt 0)

10+ Year Member



I've tried it, and it's not working.

Is there something I have to do with the modrewrite file?

The problem is that Google indexed my ip address and my regular address.

I only want my regular address indexed.

How would I direct Googlebot and any users away from the IP address?

Thanks.

jdMorgan

2:18 am on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The mod_rewrite code goes into a file called .htaccess in your web root directory where your home page is.

Your server must have mod_rewrite installed, and you (your account) must have permission to use it.

Jim

yowza

2:22 am on Nov 27, 2003 (gmt 0)

10+ Year Member



So mod_rewrite is necessary to redirect the traffic away from my IP address?

I'll have to check whether or not I am allowed to use it on my account.

Thanks.

jdMorgan

2:28 am on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you could just try it. :)

Half the time the help desk will say "No" just so they don't have to support you. mod_rewrite is powerful and requires precision, and so allowing it can significantly increase support costs. So sometimes, they say "No" even when the real answer is "Yes."

Jim

yowza

5:11 am on Nov 27, 2003 (gmt 0)

10+ Year Member



Thanks for your help! I figured it out. My .htaccess file now looks like this.

ErrorDocument 400 /notfound.htm
ErrorDocument 403 /notfound.htm
ErrorDocument 404 /notfound.htm
ErrorDocument 500 /notfound.htm
ErrorDocument 501 /notfound.htm

Redirect 301 22.33.444.555/ [widgets.com...]

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.widgets\.com
RewriteRule ^(.*)$ [widgets.com...] [R=permanent,L]

Is this line necessary or does it have any effect?

Redirect 301 22.33.444.555/ [widgets.com...]

jdMorgan

5:19 am on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think that line will work, because the Redirect directive does not have access to the requested hostname - it can only 'see' the local URL-path (filename).

Jim