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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:07:19+00:00 2026-06-17T14:07:19+00:00

I’m looking to set rules in my .htaccess file so that all files with

  • 0

I’m looking to set rules in my .htaccess file so that all files with a .php extension can be accessed by replacing the extension with just a slash (/foo/bar/ would silently load /foo/bar.php). Previously, I found this, which is kind of what I’m looking for, except it only changes /foo/bar.php to /foo/bar (notice there is no end slash).

I’m almost a completely newbie when it comes to htaccess, and about 30 minutes of tweaking with the code from the previous link produced nothing by a ton of 500 internal server errors. I’m sure it’s such a simple fix, but neither Google nor trial and error have yet to bring me any results.

Could anyone take a look at the code from the aforementioned post (copied below) and change it so that /foo/bar/ will rewrite to /foo/bar.php?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

Many thanks!

  • 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-17T14:07:21+00:00Added an answer on June 17, 2026 at 2:07 pm

    Per the comments below, the intent is to have user-visible URLs like /foo/bar/ that actually run php scripts like /foo/bar.php. In addition, you probably want users who try to load /foo/bar.php directly to be redirected to /foo/bar/ for consistency.

    #Redirect users loading /foo/bar.php to /foo/bar/
    RewriteRule ^(.*)\.php$ $1/ [R]
    
    #Rewrite /foo/bar/ (what the user sees) silently to /foo/bar.php
    RewriteRule ^(.*)/$ $1.php [L]
    

    The [R] at the end of the first rule specifies to redirect rather than rewrite, so that the user loads /foo/bar/. The $1 at the end of the second rule matches the parentheses (everything prior to the terminating slash) then tacks .php on the end. The [L] means to stop evaluating RewriteRules.

    As in my original reply, the use of a leading slash for the replacement string depends on context. With these rules you’ll be able to see the effect of the first rule since it’s a redirect. If the redirect tries to go to mydomain.comfoo/bar/ rather than mydomain.com/foo/bar/, then add a leading slash before the $1 in each rule.

    Another note – does your php script expect any query strings? There may need to be an additional tweak if it does.

    The Apache mod_rewrite reference has more details.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.