Jump to content
Sign in to follow this  
Flora Adams

.htaccess Modrewrite - Directory Index Conflict

Recommended Posts

Hi, people of the forums! :)


I'm fiddling with my .htaccess file, and I've run into some issues.


Before I continue, please note that I know next to nothing about .htaccess files, my apologies!


Now, originally a nice support rep fixed my previous .htaccess file, using this code.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
  RewriteRule (.*)\.html$ $1 [R=301]

  RewriteCond %{REQUEST_FILENAME}.html -f
  RewriteCond %{REQUEST_URI} !/$
  RewriteRule (.*) $1\.html [L]
It works splendidly!


However, I wanted a trailing slash at the end of the url. With this code, it displays "websitedotcom/about," when I'd rather "websitedotcom/about/"


It's a small issue, but it DOES return with an error if I try to add a trailing slash to the url. I could use permanent redirects to fix it, but I have a lot of pages to fix.


So, in my quest for finding codes to add a trailing slash, I tried this code that I found online.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
This works well too! Except for one problem.


I have 2 folders and 1 subdomain. The folders are using index.html files, and I specify them in links as their directory name. (websitedotcom/directoryindex/, which is an index.html)


The subdomain is for my forum, websitedotcom/forum/


Now, when I try to click websitedotcom/directoryindex/ or websitedotcom/forum/, I get a 404 error page, and I'm assuming this is because the codes I used edit out the .html file extension, add a trailing slash to it. SO, the code either doesn't find the websitedotcom/directoryindex/ folder because it's a folder, not an html file, or it's conflicting some how by editing it to websitedotcom/directoryindex//


I'll use the original code for now until I find a better solution. It's not exactly a dire problem, I was just curious as to why the new code conflicts with directory index files, and what a possible fix would be in order to display index files properly, while still having other html pages having a trailing slash.


Thanks in advance. :)

Edited by Flora Adams

Share this post

Link to post
Share on other sites

Please try this rule before your other rules:

RewriteRule ^(admin|forums)($|/) - [L]

This will end the rewriting process for the folders specified.


Note :: I have tested this on your account and verified that http://black********.com/forums/ is working fine.

Share this post

Link to post
Share on other sites

My website works perfectly now! :D

Thank you for the help, Alex! It's much appreciated.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this