403 Forbidden message when trying to access website in subfolder

Discussion in 'Apache' started by sisom, Dec 31, 2010.

  1. #1
    Hi, I have just set up a website in a subfolder of a domain, and changed the .htaccess file so that it points the new website's domain name to the subfolder, as follows:

    # REWRITE FOR NEWSITE
    ReWriteCond %{HTTP_HOST} newsite.co.uk
    ReWriteCond %{REQUEST_URI} !newsite/
    ReWriteRule ^(.*)$ newsite/$1 [L]


    (That isn't the real domain name, in case you were wondering!)
    The new site is in the folder:

    http://www.oldsite.co.uk/newsite/

    and the home page is called index.htm.

    I can access the home page if I go directly to

    http://www.oldsite.co.uk/newsite/index.htm

    or
    http://www.newsite.co.uk/index.htm

    but if I go to
    http://www.oldsite.co.uk/newsite/
    or
    http://www.newsite.co.uk

    I get the 403 Forbidden message.

    I'm sure this is something simple that I've done wrong, but I've searched on Google and found a lot of different solutions, and wasn't sure which is best.

    I am using a Fasthosts dedicated server, running Apache, and I am moderately proficient at using the command line (Fasthosts has an excellent remote control console which lets you control the server as if you were looking at its screen and typing on its keyboard).

    Many thanks in advance for any help you can give.
     
    sisom, Dec 31, 2010 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    My first guess is that your default "DirectoryIndex" is set to "index.html" so it's not finding "index.htm" when you go to the / URI. This in turn would be triggering a 403 error if you have "Indexes" turned off via the "Options" directive, or have mod_autoindex disabled.
     
    joebert, Jan 3, 2011 IP
  3. sisom

    sisom Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks very much joebert, that was it! I only had 'index.html' in the .htaccess file, now I've changed it to this:

    DirectoryIndex index.htm index.html index.php

    and it works fine. (I added the 'index.php' in case I need to use php on the homepage for a contact form I am working on.)

    Is it better for me to have "indexes" turned on, or to have mod_autoindex enabled, rather than using .htaccess for this?

    (I'm still very new at Apache, if you can point me to an online guide on how to do either of these, I should be able to follow it).
     
    sisom, Jan 22, 2011 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    "Indexes" and mod_autoindex actually work together and together they serve as a default action when "DirectoryIndex" doesn't lead to a valid file to use.

    Chances are you're going to want "Indexes" turned off globally. (which seens to be what you've got already) Doing so will prevent people from getting your directory listing by default instead of you having to go in and add an index.html / etc to each directory you don't want snooped through. Then you can go into the htaccess of a directory you do want Indexes in and turn it on for just that directory. An example of when you might want mod_autoindex to work with a directory would be the changelogs for a piece of software.
     
    joebert, Jan 22, 2011 IP
  5. sisom

    sisom Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for explaining that for me Joebert, I understand now.
     
    sisom, Jan 22, 2011 IP