homepage Welcome to WebmasterWorld Guest from 54.205.241.107
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Hardware and OS Related Technologies / Website Technology Issues
Forum Library, Charter, Moderators: phranque

Website Technology Issues Forum

    
301, 302, or silent (internal) redirect
when to use which?
brandi01

10+ Year Member



 
Msg#: 1843 posted 7:28 pm on Mar 19, 2003 (gmt 0)

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

 

jdMorgan

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



 
Msg#: 1843 posted 7:48 pm on Mar 19, 2003 (gmt 0)

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

brandi01

10+ Year Member



 
Msg#: 1843 posted 8:18 pm on Mar 19, 2003 (gmt 0)

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

brandi01

10+ Year Member



 
Msg#: 1843 posted 8:38 pm on Mar 19, 2003 (gmt 0)

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.

jdMorgan

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



 
Msg#: 1843 posted 8:39 pm on Mar 19, 2003 (gmt 0)

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

jdMorgan

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



 
Msg#: 1843 posted 8:46 pm on Mar 19, 2003 (gmt 0)

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

brandi01

10+ Year Member



 
Msg#: 1843 posted 8:48 pm on Mar 19, 2003 (gmt 0)

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

brandi01

10+ Year Member



 
Msg#: 1843 posted 8:51 pm on Mar 19, 2003 (gmt 0)

Jim is too fast. He already answered my first question.

brandi01

10+ Year Member



 
Msg#: 1843 posted 8:57 pm on Mar 19, 2003 (gmt 0)

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?).

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1843 posted 8:57 pm on Mar 19, 2003 (gmt 0)

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

jdMorgan

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



 
Msg#: 1843 posted 9:07 pm on Mar 19, 2003 (gmt 0)

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

jdMorgan

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



 
Msg#: 1843 posted 9:12 pm on Mar 19, 2003 (gmt 0)

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

brandi01

10+ Year Member



 
Msg#: 1843 posted 9:17 pm on Mar 19, 2003 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Website Technology Issues
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved