Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Best way to 301 redirect on shared server


Recommended Posts

I am on a shared server and my host says they won't turn on the rewrite engine so I was wondering what the best way to use a 301 redirect would be? I basically want to make sure the page always goes to www.xxxx.com if the user types xxxx.com

Link to comment
Share on other sites

Your host won't let you do URL rewrites? Better find another host. Or are you on a Windows server, which doesn't have a rewrite engine? Presumably there's some way to do it on Windows, but don't ask me!


I take it that both xxxx.com and www.xxxx.com go to the same site, but for SEO purposes you want to encourage www.xxxx.com usage via a 301. Unfortunately, this would involve some modification to each page. Perhaps you could stick some code at the top of application_top.php to examine the $HTTP_REFERER variable (or maybe $_SESSION['HTTP_REFERER']?) and see if it's 'xxxx.com'. If it is, do a

header('Location: www.xxxx.com' . $REQUEST_URI, 301);

or something like that. You'll have to play with it to get the right magical incantation, depending on your server setup and PHP version. Make sure you call such a header() function before anything that starts writing the page content to the browser, or you'll get a "cannot modify header" error.

Link to comment
Share on other sites

Server OS: Linux 2.6.18-164.6.1.el5.centos.plus

HTTP Server: Apache/2.2.14 (Unix)


I just did a test I found via google to see if mod rewrite is enabled and according to the test it is enabled although when I asked my hosting company they said that it couldn't be enabled on a shared server.


Yes I would prefer to have it setup like this for SEO purposes.


I guess I will see if I can use Mod Rewrite and if so this saves me alot of hassle.


If my store is in www.xxx.com/store do I need to do the Rewrite stuff for this or can I do it just on the main www.xxx.com?

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...