redirecting with .htaccess

Discussion in 'Programming/Scripts' started by David91, Aug 9, 2007.

  1. David91

    David91 New Member

    redirecting with .htaccess?

    Hello,

    im new here and i have no skill in programming at all, im simply doing this to get my website working correctally.

    The Full story:
    My website is www.seriesoftubes.co.uk/david but because if the way it is configured and they way my domain (davidoboyle.co.uk) is set up and the way that the we host is set up i cant link my domain to my webspace. so
    instead they have linked it to the main page. which is seriesoftubes.co.uk (which is a friends website/main page) My friend has given me a folder in his webspace to use as a blog and seen as i cant direct my domain to my folder/blog (because of an issue i cant fix) i am looking for a script/code to redirect people who imput davidoboyle.co.uk into my blog/folder. i know that this can be done using htaccess but i am useless at coding an unfortunatly i cannot fix it. My friend (the owner of the website) thought of this code:

    although it failed to work and gave the user an internal server error (500)
    So im looking for a peice of code to make this work. any ideas?

    just to recap:
    im looking for a peice of code to redirect people who enter davidoboyle.co.uk into their brower to seriesoftubes.co.uk/david

    Thanks for any help offered
     
    Last edited: Aug 9, 2007
  2. geekman

    geekman New Member

    Why not just create an index.html page at davidoboyle.co.uk like so:
    Code:
    <html>
        <head>
            <title>Redirecting...</title>
            <META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://seriesoftubes.co.uk/david">
        </head>
        <body>
            <a href="http://seriesoftubes.co.uk/david">If you are not redirected click here.</a<
    </html>
    
    Should work fine for you.
    Thanks.
     
  3. David91

    David91 New Member

    thing is that davidoboyle.co.uk is only a domain, there is no hosting on it, so all the hosting is on seriesoftubes.co.uk so unfortunatly i cant do as youve described, thanks for the help though.

    Any other ideas?
     
  4. falko

    falko Super Moderator

    Try something like this:

    Code:
    RewriteEngine on
    RewriteCond   %{HTTP_HOST}                 ^www\.[^.]+\.davidoboyle\.co\.uk$
    RewriteRule   ^(/~.+)         http://www.seriesoftubes.co.uk/david/$1 [R,L]
     
  5. David91

    David91 New Member

    thanks for all the help.

    i tried your code with our server and nothing happened. it doesnt redirect me and it doent destroy the server with a 500 error. i then added the line

    to the top like the other code has and it gave us a 500 error again. whats is this code used for? is it incompatable with our server or isnt it written properly?
     
  6. falko

    falko Super Moderator

    Are there any errors in Apache's error log?
     
  7. David91

    David91 New Member

    sorry for not posting this before, i found them and i just forgot.

    here is it

     
  8. David91

    David91 New Member

    bump (sorry) :p
     
  9. falko

    falko Super Moderator

    Please remove the order line from .htaccess. Then direct your browser to www.davidoboyle.co.uk (not davidoboyle.co.uk). What happens?
     
  10. David91

    David91 New Member

    when i remove the "order deny,allow" line and enter www.davidoboyle.co.uk into my browser it just goes to the main page (the same location that seriesoftubes.co.uk points to)
     
  11. edge

    edge HowtoForge Supporter

    Try this in your .htaccess file
    Code:
    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} www.davidoboyle\.co\.uk
    RewriteRule (.*) http://seriesoftubes\.co\.uk/david/index.html$1 [R=301,L]
    RewriteCond %{HTTP_HOST} davidoboyle\.co\.uk
    RewriteRule (.*) http://seriesoftubes\.co\.uk/david/index.html$1 [R=301,L]
    
     
    Last edited: Aug 13, 2007
  12. David91

    David91 New Member

    Thanks so much edge!

    seems thats sorted it. well it actually redirects me to /index.html when mines /index.php but ive made a quick instant redirect page to link between the two.

    so the problem is solved thanks :)

    this topic can be closed or whatever
     
  13. David91

    David91 New Member

    hello again =)

    the script still works (thanks again) but now im in abit of a problem. if i want to make a redirect to a subfolder its screws up and therefore doesnt work.

    for example if i wanted www.davidoboyle.co.uk/domain1 and i type in "www.davidoboyle.co.uk/domain1" into my browser i get the error message

    and the URL has changed in the address bar to

    Anyway of getting round this? like adding another Htaccess command or somthing so i could have a subdomain in "davidoboyle.co.uk"?

    thanks again for the help :)
     
  14. David91

    David91 New Member

    Bump (sorry) :D
     
  15. falcunix

    falcunix New Member

    i think , if you just want to redirect to other page, can use

    Code:
    Redirect / http://yourdirectingpage.com
    
    CMIIW
     
  16. David91

    David91 New Member

    i dont quite follow you.

    i wanna be able to redirect page C to D without interfering with the code to redirect pages A to B. and if i add another redirect into my .htaccess file it seems to screw the whole thing up.

    thanks for any help :)
     

Share This Page