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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:14:46+00:00 2026-06-12T11:14:46+00:00

I have a hard time understanding htaccess mod_rewrite and while I found several related

  • 0

I have a hard time understanding htaccess mod_rewrite and while I found several related questions + answers, I unfortunately can’t get my very specific situation to work correctly (mod_rewrite is even after hours of searching a book of seven seals to me to be honest)

I have foo.html and bar.html within my root directory. Now, I’d like to have foo.html as the default directory index (solved, easy), but from there I do not get it.

What I want to achieve is:

  1. hiding the .html extensions
    user should be able to type /bar to get /bar.html without seeing the .html (for every .html)
  2. 301 redirecting .html version
    user should be able to type /bar.html and see /bar in the url (avoid duplicate, for every .html)
  3. The most tricky part:
    As foo.html is default directory index, typing / already shows (transparently) /foo.html, but I need typing /foo.html to resolve to / as well as typing /foo to resolve to /
  • 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-12T11:14:47+00:00Added an answer on June 12, 2026 at 11:14 am

    Try putting these rules in the htaccess file in your document root:

    RewriteEngine
    
    # 1. hiding the .html extensions
    RewriteCond %{REQUEST_URI} ^/(.*?)/?$
    RewriteCond %{DOCUMENT_ROOT}/%1.html -f
    RewriteRule ^ /%1.html [L]
    
    # 2. 301 redirecting .html version
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.html
    RewriteCond %1 !foo$
    RewriteRule ^ /%1 [L,R=301]
    
    # 3. typing /foo.html to resolve to / as well as typing /foo to resolve to / 
    RewriteCond %{REQUEST_URI} ^/(.*?/?)foo(\.html)?$
    RewriteRule ^ /%1 [L,R=301]
    

    Also, make sure you have Multiviews turned off:

    Options -Multiviews
    

    The first rule has 2 conditions, the first groups the URI everything between the first / and a possible last /. The references it using %1 in the next condition which sees if the /path/to/www/document/root/%1.html is a file that exists. If both are true, it internally rewrites the URI to include a .html at the end.

    The second rule has 2 conditions, the first matches against the actual request as opposed to the URI (which can change as the rules are being applied and rewrites happen). It sees if there’s a request that ends with .html, and if so, the second condition makes sure that it isn’t foo.html request (since the last rule handles that). If both are true, then it redirects the browser to the part of the URI without the html, again using %1 to reference the grouping in the match from the first condition ([^\ ]+).

    The last rule checks if the request is for a foo or foo.html. If so, redirect removing that part of the URI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really hard time understanding routes and I hope someone can help
I have somehow hard time in understanding the following program in LOOP (you can
I have a hard time figuring this one out, it's about mistakes that can
While there are many guides for Browser Helper Objects, i have a hard time
I'm using Omron CP1L PLC and program with CX-programmer. I have hard time understanding
I have a hard time understanding the following batch script: @echo off echo b>b.txt
I have solved #103 and #105, but I have a hard time understanding #106
I'm having a hard time understanding this regex stuff... I have a string like
I created this code from a tutorial but have hard time understanding a key
I having hard time understanding importance and benefits of Annotations and so have two

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.