after becoming aware of the major lag that hits my site becaouse of the homepage redirect, i read into numerous optimization threads, proving that a 301 redirect slams out approximately 100ms to a staggering 400ms out of the total load time. On my website its around 250ms. Silly i know! On the other hand i really do need a redirect to the default language, because other domains for the different languages. What i have works, but wastest 250ms every single time.
Is there anyway this can done be faster?
Through htaccess rewrite perhaps?
CURRENTLY HAVE index.php
<?php
switch($_SERVER["HTTP_HOST"]){
case "site.org":
header('HTTP/1.1 301 Moved Permanently');
header('Location: /en/home'); # extensio .php is hidden: 'home' is a file
case "site.fr":
header('HTTP/1.1 301 Moved Permanently');
header('Location: /fr/home'); # extensio .php is hidden: 'home' is a file
etc etc
?>
I HAVE TRIED
Simply including home
that works for the first homepage beautifully, BUT the url in the browser is in this way NOT set to site.org/en/home
you just see the site.org
and all links then dont work anymore. What i need is that the homepage loads AND the url in the browser becomes /xx/home
Any and all clues are very appreciated +1
Another (probably the fastest from web server perspective) way is to use Apache VirtualHosts with
RedirectPermament
directiveWithout checking myself, I would guess that you'll see a performance increase by using mod_rewrite, because that way Apache isn't having to invoke PHP, which in turn isn't having to parse and then execute your code.
What you probably want is something like this:-
This is off the top of my head, so it's probably not completely correct, but hopefully it'll give you a good idea of what you can do. The documentation for mod_rewrite is pretty good, and it's at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html.