I have a website we'll call it domain.com, that was originally written in PHP. Every single valid URL contains the letters "php" somewhere after the "domain.com/" part.
I recently finished a complete rewrite of the site using Django, currently located at beta.domain.com
What I want to do is move the old PHP site to old.domain.com, and move the new beta site to domain.com. I want to do this without missing a beat. I want all old links to redirect to the new subdomain. This also includes linked images (that end in .php).
If yout old domain was well written (not use absolute, hard coded URIs and so on) you can the job very very easy, simply swapping the VHosts' DocumentRoot
if not then you can recur to mod_rewrite. This issue is abundantly treated on SF (#66285 can be a starting point)
If you are looking to redirect the entire old.domain.com site to domain.com (new site) then a .htaccess on old.domain.com with:
This will redirect all requests from old.domain.com/anything to the new one (the main homepage).
If you are looking for 1-to-1 redirects, for example old.domain.com/directory/file.php -> domain.com/directory/file then you would need to create mod_rewrite rules for this, assuming you are on Apache.
I just came up with a very simple solution to this. My solution only really works with Django, but I image the concept can be applied to other web frameworks.
First, direct all domains to the django app. At the bottom of the urls.py, add this:
Then create an app called "redirect", and in the views.py file, add this:
It's probably not the most efficient way to do this, but eh, it seems to work. It sure beats mucking around with .htaccess files, which seem to be impossible to test before deploying...