View Full Version : HTAccess Redirect from temp IP URL to correct URL
da8iwr
2nd August 2009, 23:19
Hi there
I have built a website on the cpanel temporary IP URL
http://host2.newworldhosting.co.uk/~greenori/
But now the site is live at
http://www.organicsuperfoods.co.uk/
Now Google has both in its index.
But of course I only want the correct URL to work, so i need some form of 301 redirect.
I have tried the none www redirect trick
RewriteCond %{HTTP_HOST} ^host2\.newworldhosting\.co\.uk\/\~greenori\/$ [NC]
RewriteRule ^(.*)$ http://www.organicsuperfoods.co.uk/$1 [R=301,L]
But it doesn't appear to be working.
Does anybody have any suggestions please?
Thanks
Ian
FireFleur
2nd August 2009, 23:25
Turn logging on if you can.
RewriteLog "/a/path/you/have/access/to/and/the/webserver"
RewriteLogLevel 9
da8iwr
2nd August 2009, 23:36
Hi Fire Fleur
Sorry can you explain what this is for please?
FireFleur
2nd August 2009, 23:47
It logs what rewrite is doing.
I had a quick scan of the reg exp, it looks ok but there has to be a problem in there or it is just not activating.
Don't leave logging on though, it is just to find out what is wrong.
Hmm:
RewriteRule ^(.*)$ http://www.organicsuperfoods.co.uk/$1 [R=301,L]
try it without the /$1 change it to $1
FireFleur
2nd August 2009, 23:56
The other thing, you have now got me actually thinking about it :) I knew I should have just stopped with explaining logging, is the \~ I would wonder if that needs to be escaped, may have to but might not.
All the reg exps are different, vim for example has 4 modes, the mod_rewrite regexp is not as flexible as most, tilde may not refer to anything special.
What I tend to do is this:
RewriteCond %{HTTP_HOST} !^www.organicsuperfood\.co\.uk
RewriteRule ^(.*)$ http://www.organicsuperfood.co.uk/$1 [R=301,L]
You pop that in what you had to redirect to organicsuperfood, see all you want do it redirect to not it (!) and that has a sort of circle defence.
FireFleur
3rd August 2009, 00:09
But don't put it on the organicsuperfood.co.uk domain or you will create a circle.
I thought it was double edged. So on the http://host2.newworldhosting.co.uk/~greenori/ domain ok.
Actually that shows the problem HTTP_HOST is probably not host2.newworldhosting.co.uk/~greenori/ it is probably host2.newworldhosting.co.uk. in which case you would have to strip the ~greenori as well as not trying to match to it.
So if you use mine, then the rewrite rule becomes:
RewriteRule ^\~greenori\/(.*)$ http://www.organicsuperfood.co.uk/$1 [R=301,L]
if the \~ is required.
ozbon
3rd August 2009, 16:47
Far easier, why not put a robots.txt file on the dev site that says
User-agent: *
Disallow: /
Then use Google's tools to remove a site from their index (http://www.google.com/support/webmasters/bin/answer.py?answer=35302) .
It'll also block any other spiders/bots from indexing your dev site. So long as you don't copy that robots.txt file from dev to live, you're fine.