Forum Moderators: phranque

Message Too Old, No Replies

User omits "index.htm" resulting in 403 Forbidden response

Problem with DirectoryIndex?

         

ForumKid1

1:36 am on Aug 25, 2007 (gmt 0)

10+ Year Member



My page is as such http://www.example.com/myfolder/index.htm

If someone goes to http://www.example.com, it will automatically redirect to http://www.example.com/myfolder/index.htm

Now, if a user removes the index.html from the url, so then the url would be http://www.example.com/myfolder/, the browser results in http 403 forbidden. Shouldn't the page used the DirectoryIndex from the virtual hosting? Here is my httpd.conf code. (I tried to move the DirectoryIndex down a few lines, but that didnt do anything). I'm just not so sure what I'm doing wrong. Everything else is working great.

<VirtualHost *>
ServerName www.example.com
#DirectoryIndex index.htm
DocumentRoot "/home/myapp"
ServerAlias example.com
DirectoryIndex index.htm

#Turn rewrite engine on
RewriteEngine On

RewriteRule ^/$ http://www.example.com/myapp/index.htm [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com$1 [R=301,L]

</VirtualHost>

[edited by: jdMorgan at 2:47 am (utc) on Aug. 25, 2007]
[edit reason] example.com [/edit]

jdMorgan

3:11 am on Aug 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/home/myapp/ is defined as the DocumentRoot. Therefore, neither /home, nor /home/myapp should ever be used in a URL. That is, /home/myapp/ is a server filepath, not a URL-path.

So, you are getting a 403 because you are redirecting the requested URL example.com/ to the URL example.com/myapp/index.htm, then the server translates that requested URL to the filepath /home/myapp/home/myapp/index.htm, which does not exist.

Because you have probably not enabled Options Indexes, no default directory listings can be served when the index file is missing, so you get a 403.

In this case, you don't need either a redirect or a rewrite. If the DocumentRoot is /home/myapp, just put the index file there at /home/myapp/index.htm and it should work as-is.

In case it is not clear, a server typically translates URLs to filepaths like this:

  • Remove the hostname, e.g. example.com
  • Prefix the remaining URL-path with the value of DocumentRoot
  • Apply mod_alias
  • Apply mod_dir
  • Apply mod_rewrite
  • Get and serve content from the resulting filepath

    So starting with example.com/, we remove the hostname, leaving only "/", then prefix that with the DocumentRoot, resulting in "/home/myapp/", and then we apply "DirectoryIndex index.htm" from mod_dir , and the final filepath for that requested URL is "/home/myapp/index.htm"

    No redirect or rewrite is required.

    Jim

  • g1smd

    6:11 pm on Aug 25, 2007 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    The most important page of a site is the root domain (home) page.

    It is very bad form for the root URL of a site to redirect to an internal page.

    You would be much better off if that redirect were changed to a rewrite.

    The user would continue to see the URL they requested, while the server would still fetch the content from that deep filepath.

    This answer from last week is for almost the same question that you asked: [webmasterworld.com...]

    wilderness

    6:14 pm on Aug 25, 2007 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    Now, if a user removes the index.html from the url, so then the url would be http://www.example.com/myfolder/, the browser results in http 403 forbidden. Shouldn't the page used the DirectoryIndex from the virtual hosting? Here is my httpd.conf code. (I tried to move the DirectoryIndex down a few lines, but that didnt do anything). I'm just not so sure what I'm doing wrong. Everything else is working great.

    I'd suggest you stop using FP to create web pages and either use another software that creates HTML extension names or change the setting in FP.

    jdMorgan

    6:57 pm on Aug 25, 2007 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Apparently, no rewrite or redirect is needed for this site. The problem is simply that some confusion exists as to the role of DocumentRoot, and an unnecessary redirect was added.

    Some Webmasters do not have a choice as to their development tools, and must use whatever their employer dictates. That may or may not be the case here.

    For the reasons above, and also to prevent confusion, I'd like to ask that we stay strictly on-topic in this forum until the original question or problem --as asked or described by the original poster-- is answered or solved. Discussion of secondary issues is then more than welcome.

    Thanks,
    Jim

    ForumKid1

    6:45 pm on Aug 27, 2007 (gmt 0)

    10+ Year Member



    The /home/myapp was merely an example. I am not redirecting to an internal folder. I just didnt want to type in a whole long path to my root inside my www folder. I'm sorry for my confusion... But here is my real VH block. The doc root looks right. I have other domains where this problem doesnt exist, yet everything is the same...

    <VirtualHost *>
    ServerName www.example.com
    #DirectoryIndex index.jsp
    DocumentRoot "/usr/oracle/oraInventory/OraHome_1/j2ee/home/applications/example"
    ServerAlias example.com
    DirectoryIndex index.jsp

    #Turn rewrite engine on
    RewriteEngine On

    RewriteRule ^/$ http://www.example.com/myapp/index.jsp [R=301,L]

    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteRule (.*) http://www.example.com$1 [R=301,L]

    </VirtualHost>

    ForumKid1

    7:06 pm on Aug 27, 2007 (gmt 0)

    10+ Year Member



    Thanks to all your help. It was actually a problem with oracle. My web.xml had the wrong welcome-file. Just in case anyone else does a search and is using oracle app server, they can check their webapp web.xml file.

    jdMorgan

    10:35 pm on Aug 27, 2007 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Glad you got it figured out and fixed!

    Thanks for posting your solution.

    Jim