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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:48:14+00:00 2026-05-31T18:48:14+00:00

When I try to remove my PHP extensions from all my files using my

  • 0

When I try to remove my PHP extensions from all my files using my .htaccess file on my Apache server, everything works great. The extensions are removed, and everything looks much better.

However, I’m having one small issue: when I would normally go to a page such as ./nonexistent.php, I would get a 404 error. But, when I rewrite my URLs, and I go to ./nonexistent, I instead get a 500 Internal Server Error.

Ideally, I would like to simply redirect my user to a custom ‘Page Not Found’ page, but I can’t currently find a way to do this.

Here’s the code I’m using:

Options -MultiViews

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php

I’ve tried setting: ErrorDocument 500 /nope, however, this doesn’t seem to have an effect either.

So, to conclude, does anyone know how to rewrite extensions, while maintaining the same functioning of the ‘Page Not Found’ system that is the default?

  • 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-31T18:48:16+00:00Added an answer on May 31, 2026 at 6:48 pm

    When you are requesting a non-existent file using the above rewrite conditions, you are running into an infinite redirect.

    If you access http://yoursite.com/i-dont-exist, the first condition is evaluating true, i-dont-exist is a non existent file, so it will try to rewrite to i-dont-exist.php which also doesn’t exist so the rewrite pattern continues until Apache limits the recursion and gives you a 500 error (essentially it is continually rewritten to i-dont-exist.php.php.php.php.php...php until you encounter the 500 error.

    You can resolve this by adding an additional check to make sure the file with the .php extension exists before rewriting.

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f  #make sure $1.php exists before rewriting
    RewriteRule ^(.*)$ $1.php
    

    If the file.php exists, then it will rewrite to it, otherwise it will not, and the 404 error page will be served.

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

Sidebar

Related Questions

I am using php and getting some utf8 string from Javascript. I try to
i'm using an htaccess script trying to remove the .php testing the .htaccess on
So, if I try to remove elements from a Java HashSet while iterating, I
I got dtd in file and I cant remove it. When i try to
can anybody explain why uploaded php files treated by a server as a text
I need to download from FTP over 5000 files being .html and .php files.
I try using xdebug with NetBeans to debug PHP. I start debug, and NetBeans
I am using the PHP SimpleXML way of working with XML files on my
I have a PHP script that fetches an image from a remote server so
I have a rule in my htaccess file to remove a www subdomain like

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.