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

  • SEARCH
  • Home
  • 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 3237374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:43:53+00:00 2026-05-17T17:43:53+00:00

I have html static files on my server. I want the access rules as

  • 0

I have html static files on my server. I want the access rules as –

  1. If user visits http://example.com/test/ he should get the contents of the file http://example.com/test.html
  2. If the user visits http://example.com/test (without the trailing slash), he gets redirected to http://example.com/test/ (which runs rule 1 and gets him the contents of the file test.html)
  3. Rules 1 and 2 should only fire if the file test.html exists.

So far, I have –

Options All -Indexes -Multiviews
# Do not return details of server
ServerSignature Off

<IfModule mod_rewrite.c>
DirectorySlash Off
RewriteEngine On
RewriteBase /

# 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.
RewriteCond %{SCRIPT_FILENAME}/ -d
RewriteCond %{SCRIPT_FILENAME}.html !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# 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
RewriteRule ^(.*)/?$ $1.html [QSA,L]
</IfModule>

Although it works for http://example.com/test, it fails for http://example.com/test/ (500 internal error)

Shouldn’t the second last line take care of trailing slashes?

[Update]
If I use Gumbo suggestions (.htaccess follows), I get a 404 for both http://example.com/test and http://example.com/test/ (with trailing slash)

Options All -Indexes -Multiviews
# Do not return details of server
ServerSignature Off

ErrorDocument 404 /404.html

# Hide .htaccess 
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

<IfModule mod_rewrite.c>
DirectorySlash On
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^[^/]+$ %{REQUEST_URI}/ [L,R=301]
RewriteRule ^([^/]+)/$ $1.html [L]

</IfModule>

[Update 2]
I have given up. The code below works, but instead of forcing everything end with a / (http://example.com/test/), it removes the trailing slash (http://example.com/test). On the bright side, it ensures that the content is pointed to by only one url, preserving SEO. I’m going to live with it for now.

Options All -Indexes -Multiviews
# Do not return details of server
ServerSignature Off

ErrorDocument 404 /404.html

# Hide .htaccess 
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

<IfModule mod_rewrite.c>
DirectorySlash On
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$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 extesion.
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]


</IfModule>
  • 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-05-17T17:43:53+00:00Added an answer on May 17, 2026 at 5:43 pm

    Try these rules:

    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^[^/]+$ %{REQUEST_URI}/ [L,R=301]
    RewriteRule ^([^/]+)/$ $1.html [L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML structure and want to convert it to an accordion. <div
I have HTML that includes symbols such as the Trademark TM as superscript (™).
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have HTML code like this : <div> <a>Link A1</a> <a>Link A2</a> <a>Link A3</a>
I have HTML code edited by FCKEditor stored in a database and would like
In a stylesheet i have: * HTML BODY { padding-right: 0px; padding-left: 0px; padding-bottom:
I have an HTML Mail template, with a place holder for the image. I
I have an HTML page (say welcome.html) which contains an iframe to a page
I have a HTML page that scrolls up and down (not a lot, but
I have some HTML that looks like this: <ul class=faq> <li class=open> <a class=question

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.