Results 1 to 5 of 5

Thread: Htaccess not working for sub directories.

  1. #1
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default Htaccess not working for sub directories.

    I really new to htaccess and regular expressions, and I'm getting a little lost.

    I have a small script that I got from a tutorial that basically removes the file extension and adds a trailing slash to the end if needs be.
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^/]+)/$ $1.php 
    
    # Forces a trailing slash to be added
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    This code works fine for files in my main directory. I have a couple files that are in sub directories though and it seems the rules aren't being carried through.

    so for files at example.com/file.php the mod rewrite works fine and it allows the url to be example.com/file/

    but for files at example.com/sub/file.php if I try to use example.com/sub/file/ I get a 404 page.

    I think I understand that the condition its checking against is only looking in the root, but I don't know enough to add in another condition or rule to check a sub directory as well.

    any help would be greatly appreciated.

  2. #2
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    I am really on thin ice here, but since no one else suggests anything I thought of asking if you have tried to put a copy of the .htaccess file inside the subdirectory ? I know you need to do that sometimes but I don't know if it will work in this case.

  3. #3
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    Yes, I did try that. One of the first things I thought about actually.

    What happened was that it removed the sub directory part from th url.

    so example.com/folder/file/ would become example.com/file/ and i'd get the 404 again

  4. #4
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    then you have probably also seen this post
    I have no idea what the hieroglyphs mean, but it seems like they are talking about the same stuff

  5. #5
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    I look into that post, they are having the same problem, yet still no real solution with the directories.

Bookmarks

Posting Permissions

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