| .htaccess vs in page header redirection
|
steveonz

msg:4174595 | 9:44 am on Jul 22, 2010 (gmt 0) | Hey, I am working on a geo redirection script and want to redirect cusomters to a new directory. What is best, htaccess or in page header redirect? This is the code I plan to use:
if ($countrySHORT == "NZ") { Header("Location: testnz/index.html"); } else { // Otherwise, redirect them to US site Header("Location: testus/index.html"); } I want to be able to place that code in an include and have it on a number of pages but I don't want to edit the pages individuality with the new url, I just want to do a folder redirect. For example all people from NZ are sent to the NZ/ dir but Lets say the page is index.html or simon.html it will redirect it to the nz/index.html or nz/simon.html version. I'm not a fan of telling each page what the new page is. Is this possible?
|
videomike

msg:4175319 | 12:53 pm on Jul 23, 2010 (gmt 0) | Sound like a good way to do it - have you actually tried it?
|
jdMorgan

msg:4175431 | 5:02 pm on Jul 23, 2010 (gmt 0) | You could use the "auto-prepend" feature of PHP to include the code in every page. If you do use a redirect, then specify a 301 redirect or a 302 redirect as desired. A 301 will tell search engines to update the URL in their search results, whereas a 302 will keep the original URL, but use and show the content from the new URL. However, if you do not wish to expose the "country-based" subdirectory to users and search engines at all, then you should not use a redirect, but rather use an internal rewrite (e.g. Apache mod_rewrite URL-to-filepath translation). Alternatively, your script should "open and read in" (PHP file include) the correct "country-based" files, and output their content to the browser directly without changing the URL. Keep URLs and filepaths separate in your head -- They are not at all the same thing, and understanding the difference makes these kinds of projects much easier to understand. Mod_rewrite can change the file associated with a URL. Jim
|
steveonz

msg:4175620 | 11:46 pm on Jul 23, 2010 (gmt 0) | Thanks for the feedback, yes I have tried it and it works superb, I'm not really sure if it will affect me much with the bots because the likelihood of a NZ based bot coming around is very slim. I will do some more research on this topic, thanks!
|
|
|