Monday, April 25, 2011

how to write this in htaccess

I am using godaddy and what I want to do is when someone types in a domain address I want it to automatically redirect to a folder rather than placing the files on the root so its more organised.

How do I write this in .htaccess?

From stackoverflow
  • Do you use GoDaddy for your DNS only, or for your web hosting as well? Their economy plan does not allow you to host multiple websites (http://www.godaddy.com/gdshop/hosting/shared.asp?ci=9009)

    GoDaddy has a nice online help, you should take a look: http://help.godaddy.com/article/4688

  • Check this link, it worked for me

    http://helpdesk.hostmonster.com/kb/index.php?id=308&mod_id=2&x=

  • RewriteEngine on
    RewriteRule (.*) subfolder/$1 [L]
    

    The L is needed so that if there are other rules they don't get executed (think infinite loop); this is written as a catch-all.

  • Simple Rewrite

    Unless a condition exists the Rewrite will not do stuff. Here's a code that will actually work in no subfolder is specified. e.g http://domain.com will be redirected to http://domain.com/subfolder/somefile

    You can also point it to a subfolder and not a file, just remove the somefile.php and your set. Remember to change the value of "DOMAIN" and "SUBFOLDER"

    #Turns the engines on!
    rewriteEngine on
    # Checks Condition, "Does it have a subfolder specified?"
    rewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    # Does its Rewrite Magic
    rewriteRule ^$ http://%{HTTP_HOST}/subfolder/somefile.php [R,L]
    
    solomongaby : i would also add a code to the redirect [L,R=301] for example

0 comments:

Post a Comment