Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Quick mod_rewrite question

  • 04-09-2004 01:50PM
    #1
    Registered Users, Registered Users 2 Posts: 1,569 ✭✭✭


    Hi,

    I'm moving a load of pages from their own domain to a subdomain on another site. I want to send a http 301 status when someone requests the old file, with the correct location header for the file. I've written a php script that will do this, so when you type http://www.foo.com/redirect.php?url=bar.html you get a 301 which redirects to http://foo.new.com/bar.html. Now all I need is to set up mod rewrite so when someone tries to access http://www.foo.com/bar.html, it redirects them to the php script, which then sends them to the correct new location.

    Unfortunately, I know nothing about mod rewrite. I've tried googling, but all the results I got seemed a little over my head.

    This should be a fairly simple rule, right? Can anybody help me out with it?

    TIA


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Ah, mod_rewrite, the Apache module of the Gods. :)

    But in this case, unless you need to leave some content accessible in foo.com, I'm not sure why you need it. If all the pages/resources under foo.com are being redirected to foo.new.com, all you need is RedirectPermanent (or of course Redirect with a status):
    RedirectPermanent / http://foo.new.com/
    
    Now if sites are on the same server and you want to drop the foo.com VirtualHost altogether, that's another matter entirely, and we can go back to mod_rewrite (see the first bullet point in the flags section of RewriteRule).
    RewriteRule /(.*) http://foo.new.com/$1 [R=301]
    
    HTH,
    adam


  • Registered Users, Registered Users 2 Posts: 1,569 ✭✭✭maxheadroom


    Thanks - that's a much simpler way to go about this :)


Advertisement