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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:30:49+00:00 2026-05-27T09:30:49+00:00

I use .htaccess to display my 404 page, while showing the requested URL in

  • 0

I use .htaccess to display my 404 page, while showing the requested URL in the browser instead of the actual 404 URL. To do so, I have this line in my .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /404.php [L]

This works good whenever I go to a non-existent file (i.e. blalba.php).

The problem is: When I try to go to my main site dir (i.e. http://example.com/), I see the 404 page. When I directly go to my index file (i.e. http://example.com/index.php), everything works just fine.

How could I modify the .htaccess to not redirect my main dir?

So that, in fact, the main dir is excluded from the rewrite code above.

ANSWER:

See answer below and adding RewriteCond %{REQUEST_FILENAME} !-d solved the problem!

  • 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-27T09:30:50+00:00Added an answer on May 27, 2026 at 9:30 am

    I’m pretty sure you just forgot to tell apache that it needs to “default” to index.php if nothing is precised in the url. Here’s how you do:

    <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>
    

    Other answer about 404

    I’ve had the same problem a few days ago. It’s simple: assign the error document to 404.php. Whenever there’s a 404, the server makes an internal redirection so that it can craft properly the web page.

    So here’s a sample of my vhost config:

    <VirtualHost *>
        ServerName x.fr
        ...
        ErrorDocument 404 /404.php
        # activate rewrite engine:
        RewriteEngine On
    
        # *IMMEDIATELY* treat 404
        # if 404.php then stop immediately
        RewriteRule /404.php - [QSA,L]
    
        # From now on your can apply all your rules:
        ...
        ...
        ...
        # Sample of how I do a 404:
        RewriteCond %{ENV:PATH_LOCAL} notfound
        # "not found" 404 :
        RewriteRule .* - [R=404,L]
    </VirtualHost>
    

    With all that you should be able to create your own rewriterules with proper 404 “filtering”.

    Hope this helps!

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

Sidebar

Related Questions

I use this line in my .htaccess file to automatically add a trailing slash
I am completely stumped with how to use .htaccess and I have an issue
I have a problem, surprise ;) I use .htaccess in Apache and have a
I have a directory protected by htaccess. Here is the code I use now:
I have a page (ie www.mysite.com/products.php?catid=5 ) in which I use the $_REQUEST[catid'] to
I currently use .htaccess and PHP to parse URLs in the following way: URL
I have a subdomain setup as onlinedev.domain.com I need to use htaccess to rewrite
I lately started to use htaccess to rewrite my URL's but i've got some
I'm trying to modify my web page, which I currently use QueryStrings to display
I want to use htaccess rewrite to display single pages without the extensions. http://site.com/account

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.