Results 1 to 3 of 3

Thread: Mod_rewrite with directories

  1. #1
    Join Date
    Feb 2008

    Mod_rewrite with directories

    Hi All,

    I've been working on converting a page which was managed entirely by Joomla into static files which are wrapped with a header/footer. I know it sounds kind of crazy but there is reasoning for this. Anyway I used a spider to download the entire website as static HTML files, and then I wrote a parser script which went through all of those files, turned them into PHP files, removed the consistent header/footer and replaced those with header and footer includes. This all worked quite well and without any problems. The only problem I have found is that for whatever reason the directory structure is somewhat unusual. For instance you may have this:




    While the directory blah will not contain a file index/default/etc so going to the directory blah by itself simply pulls up a directory listing.

    What I am hoping is there is a way to use mod_rewrite to effectively say if there is no default file in a directory then look for a filename that has the same name as the directory with the .php extension and display it. I have already written in a bit of code in the .htaccess file to deal with the .php extension and simply allow it to work minus this extension but despite quite a bit of searching I haven't found any suggestions on how to achieve above. I imagine somewhere it is out there but I am probably simply not using the right search query. If so I apologize.

    Anyway hoping someone can offer me some insight into how to achieve this.


  2. #2
    Join Date
    Feb 2008
    Hi All,

    Update. Amazing how once you ask a question you suddenly think of something. I came up with this tiny addition:

    RewriteCond %{SCRIPT_FILENAME}/index.php !-d
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

    It works for the most part with the one exception being that if I have a trailing slash at the end of the URL IE blah/ instead of just blah it fails. I am guessing because it fails to pull up blah/.php instead of blah.php. I am researching how to remove the /. Hopefully I find something. If anyone know's that would be great.


  3. #3
    Join Date
    Mar 2011
    I have the same problem on my site, you gotta have the trailing slash. I think that's just the way apache is set up. I wanted all the files on my site to look like they had there own directory, but settled to just have them all look like name_of_file.html... it's kind of sweet actually, I have 3 php files doing all the work and it looks like there's hundreds of html files.

    Google doesn't put the slash at the end so I needed to make the pages look like html files... something to think about.

    my site is emulation-station.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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