Welcome to WebmasterWorld Guest from 54.163.115.193

Forum Moderators: phranque

301, 302, or silent (internal) redirect

when to use which?

   
7:28 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



OK, thanks to everyone here I can do 301 and 302 redirects pretty well.

Question is, how do I do a silent (internal) redirect, and should I (or when should I)?

Reason is this: Website is accessible as either www.domain.com or domain.com, but the secure certificate is only for www.domain.com. I would like to redirect all the domain.com requests to www.domain.com. Should I use 301, 302, or internal? I do not have access to http.conf.

Thanks
-brandi

7:48 pm on Mar 19, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



brandi01,

In order for your certificate to work, you'll need to use a 301 or 302 external redirect. Unless you plan to get a certificate for the www-less domain soon, I'd use a 301. For use in .htaccess:


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

Jim

8:18 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



Thanks Jim,

That's pretty much what I thought, just wanted to make sure.

I'm also renaming some files to more user friendly names (dsc_rps.htm to product-name.htm). It seems like a 301 redirect would be best here for spiders. Would you mind telling me when one would use a silent (internal) redirect?

Thanks again
-brandi

8:38 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



Oops, sorry, one more question.

When using the above rewrite, now when I go to
[mysite.com...]
I get redirected to [mysite.com...]
which is half correct, BUT blah.htm should return a 404 (blah.htm does not exist).

Now I'm stuck again.

8:39 pm on Mar 19, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



brandi,

For renaming pages, a 301 is the way to go. You can remove these redirects once most of the incoming external links to them have been corrected, the search engines have stopped accessing the old URLs, and once most of your users seem to have updated their bookmarks.

Internal redirects are used mostly for site security issues, such as redirecting image hot-linkers to an alternate image or for invoking a bad-bot trap from an innocent-looking URL, and for making scripts spider-friendly by rewriting spider-friendly URLs to those required to pass parameters to your scripts.

Jim

8:46 pm on Mar 19, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Brandi,

I'm not sure, since you did not say what you did get instead of a 404. But I'll take a guess.

If you are using the ErrorDocument directive, be sure that you are not specifying a canonical URL.

ErrorDocument 404 [yourdomain.com...] is incorrect. Use:
ErrorDocument 404 /yourerrorpage.html

Try the server header checker [webmasterworld.com] to investigate what your server returns from each domain for non-existent pages. For the non-www domain, you should get a 301 response accompanied by the URL including the www domain. For the www domain, you should see a 404 response.

Jim

8:48 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



two more questions (see first above Jim's last reply above)

second question: what does the 1 following the second $ do in this rule?
RewriteRule ^(.*)$ [mydomain.com...] [R=permanent,L]

Thanks again!
-brandi

8:51 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



Jim is too fast. He already answered my first question.
8:57 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



Sorry, I will try to explain better.

I was using the server header checker, which is where I saw what was happening.

For the www.mydomain.com/blah.com non-existent page I get a 404 response (good).

For the mydomain.com I get a 301 response (good).

For the mydomain.com/blah.htm non-existent page I get a 301 response (is this correct even though blah.htm does not exist?).

8:57 pm on Mar 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It contains the string that was back-referenced in the first part using (.*)

In this case it is the relative url requested
ht*p://www.yoursite.com/this_is_the_string_in_$1

9:07 pm on Mar 19, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



brandi,

mod_rewrite operates in the Apache API phase where URLs are translated to filenames. Therefore, the 301 is invoked before Apache has checked to see that the file does not exist. When the user-agent follows the 301 and re-requests "blah.hrml" from the "correct" domain, a 404 is returned.

So you are seeing the expected behaviour.

Jim

9:12 pm on Mar 19, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Brandi,

...and as birdman points out, $1 is used to backreference the page name in the pattern on the left side of the RewriteRule. Without the backreference, all requests for all resources on yourdomain.com would be redirected to the default page of www.yourdomain.com. So, for example, a request to [yourdomain.com...] would be redirected to [yourdomain.com...] which would normally be [yourdomain.com...] - Not a pretty sight if unintended!

Jim

9:17 pm on Mar 19, 2003 (gmt 0)

10+ Year Member



Thanks Jim and Birdman!

Sorry to seem so dense, but I spent a good part of the day site searching for answers and just couldn't find what I needed in the hundreds of returned threads. Was clear as mud. Now I can see through the mud. :)

-brandi

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month