Forum Moderators: coopster

Message Too Old, No Replies

php redirect vs htaccess redirect

         

MisterT

5:58 am on Dec 28, 2009 (gmt 0)

10+ Year Member



i've got a bunch of URLs i need to redirect out to other websites...any thoughts from anyone on using a php redirect vs htaccess?

For example, I could set this up in a php redirect file as something like:

/go.php?id=name

or in hataccess as a 302 redirect:

/go/name

Are there advantages/disadvantages to either? I'm really just not that skilled in this, any advice is much appreciated!

TheMadScientist

12:25 am on Jan 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



IMO it really depends on the situation and how often the redirects will need to be run... If they happen 'all the time' (meaning often, for a majority of the site or highly trafficked pages) I usually use .htaccess. If they are only going to run once in a while, then I usually opt for PHP.

One of the most important things is to set a redirect status in either. Running a 302 is really not recommended in either the .htaccess file or PHP... You should set the proper status code to give SEs (and visitors) the reason for the redirect so the next visit is handled correctly.

You can find status codes here:
Redirect Status Codes [w3.org]

MisterT

12:52 am on Jan 1, 2010 (gmt 0)

10+ Year Member



thanks for the advice. i've been using 302 redirects in htaccess when i send users out to other websites (for example, when they click an affiliate link). thus far it has worked fairly well. i've tried using a php redirect file but did not find it as reliable. do you know if there is a better status code to use for that htaccess redirect? i thought a 302 was ok for all sorts of non-permanent redirects?

TheMadScientist

1:14 am on Jan 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In that case, personally, I'd use a 301, permanent, because the location of the resource requested is permanently located at the location the visitor is being redirected to and that's where the resource should be requested from on every visit. IMO It's much the same as if you moved a page from your site there since you link to an internal location and redirect to an external one...

I personally don't recommend it, but if you would like it to be temporary, you could use a 307 Temporary or 303 See Other, but this is not the intended use of those status codes. A 302 Found is basically a 'catch-all' for an 'undefined' redirect and SEs have had known issues with handling them.

All the status codes and their intended uses are listed on the link I provided, and personally, I think 301 is the best option for what you are doing, but you may find one you think fits better knowing your exact situation.

MisterT

8:24 pm on Jan 3, 2010 (gmt 0)

10+ Year Member



thanks for the additional advice... my worry about using a 301 permanent is that the location of the redirect may change. for example, today it redirects to widgets.com but in 2 months it could redirect to bigwidgets.com. i thought if i use a 301 the url should never change. no?

TheMadScientist

1:34 am on Jan 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I can see your point, but personally I've changed 301s before when the new location of the information changes... IOW the information you were looking to find at 'blah location' on 'example.com' has been permanently relocated to a new location. Sometimes that location changes, but the information is permanently moved from the location you originally requested. A 307 is temporary though, so I would think you could use it... A 302 is basically saying 'I don't know' it's a 302 Found, which is basically an 'undefined' or 'IDK' redirect, which is not what I would want to say. If it's worked though, then obviously you could keep using it.

MisterT

8:04 pm on Jan 4, 2010 (gmt 0)

10+ Year Member



It's working for me, I just don't want to piss off any google gods or whatever. I have the nofollow attribute on the redirects, so I assume it is cool. I'm not trying to pass any link juice to these links so I don't need a 301...but if a 301 is better practice than a 302 I can change them...

Thanks for your feedback. If anyone else knows whats up please chime in. :)

TheMadScientist

8:25 pm on Jan 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd recommend asking in the Apache Forum [webmasterworld.com] if you want more input... It's where status code questions are usually asked, so you might get a better response than in here.