Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:45:01+00:00 2026-06-13T20:45:01+00:00

I have a static site with the following file/folder structure: index.html /foobar/ index.html bob.html

  • 0

I have a static site with the following file/folder structure:

  • index.html
  • /foobar/
    • index.html
    • bob.html
    • alice.html

I’d like to achieve the following:

  • remove all .html extensions. ✔ works
  • remove index.html (resp. index). ✔ works
  • I want files to end without trailing slash. ✔ works
    • if someone adds a trailing slash, redirect to URL without trailing slash. ✘ doesn’t work
  • I want “folders” (actually index.html files inside a folder) to end without trailing slash. ✘ doesn’t work
    • if someone adds a trailing slash, redirect to URL without trailing slash. ✘ doesn’t work

So the following URLs should work:

  • example.com/ (actually: /index.html)
  • example.com/foobar (actually: /foobar/index.html)
  • example.com/foobar/bob (actually: /foobar/bob.html)
  • example.com/foobar/alice (actually: /foobar/alice.html)

The following requests should redirect (301):

  • example.com/foobar/ redirects to: example.com/foobar)
  • example.com/foobar/bob/ redirects to: example.com/foobar/bob)
  • example.com/foobar/alice/ redirects to: example.com/foobar/alice)

I see that this would create a problem when a file /foobar.html exists: when someone visits /foobar, it is not clear whether the directory or the file is requested. However, I will make sure that this never happens.


At the moment, I have this .htaccess:

# Turn MultiViews off. (MultiViews on causes /abc to go to /abc.ext.) 
Options +FollowSymLinks -MultiViews

# It stops DirectorySlash from being processed if mod_rewrite isn't. 
<IfModule mod_rewrite.c>

    # Disable mod_dir adding missing trailing slashes to directory requests.
    DirectorySlash Off

    RewriteEngine On

    # If it's a request to index(.html) 
    RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\  [NC]
    # Remove it. 
    RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L]

    # Add missing trailing slashes to directories if a matching .html does not exist. 
    # If it's a request to a directory. 
    RewriteCond %{SCRIPT_FILENAME}/ -d
    # And a HTML file does not (!) exist.
    RewriteCond %{SCRIPT_FILENAME}.html !-f
    # And there is not trailing slash redirect to add it. 
    RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

    # Remove HTML extensions. 
    # If it's a request from a browser, not an internal request by Apache/mod_rewrite. 
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    # And the request has a HTML extension. Redirect to remove it. 
    RewriteRule ^(.+)\.html$ /$1 [R=301,L]

    # If the request exists with a .html extension. 
    RewriteCond %{SCRIPT_FILENAME}.html -f
    # And there is no trailing slash, rewrite to add the .html extension. 
    RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]

</IfModule>

What would I have to change/remove/add in my .htaccess? I don’t understand much of it. I tried to remove the block commented “Add missing trailing slashes to directories if a matching .html does not exist”, but this didn’t help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:45:02+00:00Added an answer on June 13, 2026 at 8:45 pm

    Right above your # Add missing trailing slashes to directories if a matching .html does not exist. rule, try adding this rule that redirects when there is an html file and the request is NOT a directory AND there’s a trailing slash:

    # if request has a trailing slash
    RewriteCond %{REQUEST_URI} ^/(.*)/$
    # but it isn't a directory
    RewriteCond %{DOCUMENT_ROOT}/%1 !-d
    # and if the trailing slash is removed and a .html appended to the end, it IS a file
    RewriteCond %{DOCUMENT_ROOT}/%1.html -f
    # redirect without trailing slash
    RewriteRule ^ /%1 [L,R=301]
    

    This shouldn’t conflict with the redirect rule following it because its conditions check for the exact opposite.


    EDIT:

    To handle the index.html thing, you need to change this rule that you have, which is appending the trailing slashes:

    # Add missing trailing slashes to directories if a matching .html does not exist. 
    # If it's a request to a directory. 
    RewriteCond %{SCRIPT_FILENAME}/ -d
    # And a HTML file does not (!) exist.
    RewriteCond %{SCRIPT_FILENAME}.html !-f
    # And there is not trailing slash redirect to add it. 
    RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
    

    To:

    # Add missing trailing slashes to directories if a matching .html does not exist. 
    # If it's a request to a directory. 
    RewriteCond %{REQUEST_FILENAME}/ -d
    # And a HTML file does not (!) exist.
    RewriteCond %{REQUEST_FILENAME}/index.html !-f
    # And there is not trailing slash redirect to add it. 
    RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]    
    

    This checks that the index.html file is missing from the directory before adding the trailing slash. The reason you must have this is because of the information disclosure security issue when missing the trailing slash will actually expose all of your directory contents if you don’t have the trailing slash. Now, add these rules to remove the trailing slash when there’s an index.html:

    RewriteCond %{REQUEST_FILENAME} -d
    # And a HTML file exists.
    RewriteCond %{REQUEST_FILENAME}/index.html -f
    # And there is a trailing slash redirect to remove it. 
    RewriteRule ^(.*?)/$ /$1 [R=301,L]    
    

    Now add these rules right after to explicitly display the index.html when there is no trailing slash (note no R=301 in the rule’s flags):

    RewriteCond %{REQUEST_FILENAME} -d
    # And a HTML file exists.
    RewriteCond %{REQUEST_FILENAME}/index.html -f
    # And there is no trailing slash show the index.html. 
    RewriteRule [^/]$ %{REQUEST_URI}/index.html [L]    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many static images under a directory in my site structure, and I'm
I have developed a site, which has some static pages. Like explore, home, feedback.
I have the following rake file to create a static version of my sinatra
I've made a sub-domain for static content (static.site.com) and I have the following .htaccess:
We have to develop an Ecommerce site with 20+ pages of static content which
I have static combo box in html with some default value already selected and
I am looking into serving my static site with Amazon S3. I have created
I got the following XML file (Data.xml): <root> <sitecollection name=1A> <site name=1B> <maingroup name=1C>
i'm developing an interface to retrieve a file from sharepoint. i have the following
Lets say I have the following one-to-many relationship: Site has many Users User belongs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.