Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
htaccess shows "Not Found" if directory does not exist

I want rewrite everything that matches <domain>/something/mypage.htm to something.php?pid=mypage, so I wrote the following .htaccess file:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).htm$ $1.php?pid=$2
DirectoryIndex home.php

On my old webhosting provider, the rules worked as expected, but on the new provider, it says "Not Found" when I try to open <domain>/something/index.htm or similar. But when I create a directory called something, the rewrite rule works as expected.

Is anyone having any idea what's wrong here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It looks like MultiViews is perhaps enabled on the new server and this will conflict with your mod_rewrite directive.

With MultiViews enabled and you request /something/mypage.htm (when /something.php exists as a physical file), mod_negotiation will issue a subrequest for /something.php/mypage.htm (that's /something.php with path-info of /mypage.htm) before your mod_rewrite directive is able to process the request, so no pid parameter is passed. (Your directive does not match a dot in the first path segment, so the subrequest by MultiViews does not match.)

The 404 will result from either Apache, if AcceptPathInfo Off is set (perhaps in the server config), or from your script because the pid parameter is not being passed.

When you create a subdirectory called something, MultiViews does not rewrite the request since it already matches something, ie. the directory by that name.

You need to ensure that MultiViews is disabled at the top of your .htaccess file:

Options -MultiViews

NB: MultiViews is not enabled by default on Apache, but some shared webhosts do enable it for some reason. It makes extensionless URLs "magically" work out of the box, but actually causes many more problems if you are not expecting it.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!