Results 1 to 3 of 3
  1. #1

    Default pages not loading without "/"

    Hard to describe the situation in the subject so here is the spill:

    CentOS Server
    cPanel

    While getting my new server ready to move my main site over to I have a problem with default PhP pages not loading correctly. I set index.php to be a default page in .htaccess but the default page won't load unless a trailing "/" is used in the url.

    Example:

    http://www.domain.com/ ----- Works fine, loads index.php

    http://www.domain.com ----- Does not load index.php or any other default page



    I'm sure this is one of those easy settings I have just overlooked . Any suggestions?

  2. #2
    Join Date
    Apr 2003
    Location
    San Jose, CA.
    Posts
    1,622
    Check settings described here...

    http://httpd.apache.org/docs/2.0/mod/mod_dir.html

    DirectorySlash On
    should be default.. but might have gotten changed somehow... ?

  3. #3
    I think the above settings are Available in version 2.0.51 and later

    Another solution was to add a .htaccess rewrite rule that adds the trailing slashes to these urls.


    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !sample.php
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301]

    Explanation of this add trailing slash .htaccess rewrite rule

    The first line tells Apache that this is code for the rewrite engine of the mod_rewrite module of Apache.

    The 2nd line sets the current directory as page root.

    RewriteCond %{REQUEST_FILENAME} !-f makes sure that files that are existing will not get a slash added. You shouldn't do the same with directories since this would exclude the rewrite behavior for existing directories.

    The line RewriteCond %{REQUEST_URI} !sample.php excludes a sample url that shouldn't be rewritten. This is just an example - if you don't have any file or url that shouldn't be rewritten, remove this line.

    The condition RewriteCond %{REQUEST_URI} !(.*)/$ finally fires when a urls doesn't contain a trailing slash - this is all what we want. Now we need to redirect these url with the trailing slash:

    RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301] does the 301 redirect to the url with the trailing slash appended for us.
    Last edited by Linuxsurgeon; 01-24-2007 at 12:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •