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

163
Views
Remove .php extension

I have two pieces of code that removes the .php extension.

Solution 1:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Solution 2:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

directory is a directory

page is a page

problem with solution 1:

if you go to domain.com/directory, it is supposed to show domain.com/directory/index.php but the index.php does not appear and it just shows a 404 error page.

problem with solution 2:

if you go to domain.com/directory/page/haha-lol-blah-blah, the page domain.com/directory/page shows up, no matter what is after the page.


is there a solution for both problems?

here is what i need:

domain.com/directory -> shows the page: domain.com/directory/index.php
domain.com/directory/page -> shows the page: domain.com/directory/page.php
domain.com/directory/page/haha-lol-blah-blah -> invalid page (404)
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I believe this is working now with this code:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
over 4 years ago · Santiago Trujillo Report

0

Try it like this,

#incoming request neither a file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)$ $1.php [L]
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!