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 6905117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:08:41+00:00 2026-05-27T08:08:41+00:00

On my website, when somebody requests a directory, I want it to remove the

  • 0

On my website, when somebody requests a directory, I want it to remove the ‘/’ and add ‘.html’ (minus the quotes, of course).

Example:
If someone goes to domain.com/directory/ it should redirect to domain.com/directory.html/ and the same should stand for: domain.com/another-directory/ should redirect to domain.com/another-directory.html.

I would like to place a line (or two) of code to my htaccess file that will make any directory (URL ending with /) redirect to URL.html (removing the / of course).

I would also like it to visually redirect, so the user will actually see it change to .html.

I’m quite a novice web programmer, and any help is greatly appreciated.

Note: I did use Redirect /directory /directory.html and that worked, but that requires a lot of extra coding, and I would much prefer one simple statement to cover all directories.

  • 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-27T08:08:42+00:00Added an answer on May 27, 2026 at 8:08 am

    This is going to be a bit difficult with htaccess, I assume you want to do the following:

    1. If someone accesses a directory that isn’t the root (simply http://domain.com/), redirect them to the directory name ending with .html
    2. After the get redirected, internally rewrite the .html back to the directory so apache can serve the directory.

    First one is straightforward:

    # check to make sure the request isn't actually for an html file
    RewriteCond %{THE_REQUEST} !^([A-Z]{3,9})\ /(.+)\.html\ HTTP
    # check to make sure the request is for a directory that exists
    RewriteCond %{REQUEST_FILENAME} -d
    # rewrite the directory to 
    RewriteRule ^(.+)/$ /$1.html [R]
    

    Second part is tricky

    # check to make sure the request IS for an html file
    RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ /(.+)\.html\ HTTP
    # See if the directory exists if you strip off the .html
    RewriteCond %{DOCUMENT_ROOT}/%2 -d
    # Check for an internal rewrite token that we add
    RewriteCond %{QUERY_STRING} !r=n
    # if no token, rewrite and add token (so that directories with index.html won't get looped)
    RewriteRule ^(.+)\.html /$1/?r=n [L,QSA]
    

    However, if what you just have is a bunch of files called directory.html, directory2.html, directory3.html, etc. and you want to make it so when someone enters http://domain.com/directory2/ into their address bar they get served the contents of directory2.html, it will be much simpler:

    # check to make sure the request isn't actually for an html file
    RewriteCond %{THE_REQUEST} !^([A-Z]{3,9})\ /(.+)\.html\ HTTP
    # check to see if the html file exists (need to do this to strip off the trailing /)
    RewriteCond %{REQUEST_URI} ^/(.+)/$ 
    RewriteCond %{DOCUMENT_ROOT}/%1.html -f
    # rewrite
    RewriteRule ^(.+)/$ /$1.html [L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody explain what ASPXAuth cookie does? My website uses forms auth and I
My website makes a lot of requests. I often need to cancel all current
My website was infected by a trojan script. Somebody managed to create/upload a file
I'm want to make website have a textbox and a save button. When you
I want to build a stock website with Django, and I found a Javascript
Can Somebody know the FREE Automated Testing Tool for testing asp.net website which tests
Could somebody please give me a few pointers on how to add a sliding
Hello i have a website and a blog, i want to display my self
I'm helping my sister convert a website that somebody did for her in flash
I am creating a website which is not completed yet. Somebody suggested me to

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.