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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:41:56+00:00 2026-05-31T08:41:56+00:00

I have in my .htaccess the following code: RewriteEngine On RewriteRule ^/?([^/\.]+)/?$ $1.php [L]

  • 0

I have in my .htaccess the following code:

RewriteEngine On
RewriteRule ^/?([^/\.]+)/?$ $1.php [L]
RewriteRule ^/?([^/\.]+).php$ $1/ [R,L]


RewriteRule ^/?([^/\.]+)/?$ $1.php [L]
is working fine. What this is doing is taking a url like http://www.example.com/whatever and making it read the page as http://www.example.com/whatever.php.

However, what I’d like to be able to do is take a url like http://www.example.com/whatever.php and automatically send it to http://www.example.com/whatever, hence the second line of the code. However, this isn’t working. What its doing now, is as soon as it comes across a link ending in .php, the url becomes http://localhost/C:/Sites/page/whatever/, and pulling a 403: Forbidden page.

All I want to know is what I can to so that http://www.example.com/whatever.php will be read as http://www.example.com/whatever, and that if http://www.example.com/whatever.php is entered into the URL bar, it will automatically redirect to http://www.example.com/whatever.

Does that make any sense?

EDIT

Ok, so it appears I wasn’t all too clear.. basically, I want /whatever/ to read as whatever.php while the URL still stays as /whatever/, right? However, if the URL was /whatever.php, I want it to actually redirect the users URL to /whatever/, and then once again read it as whatever.php. Is this possible?

  • 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-31T08:41:57+00:00Added an answer on May 31, 2026 at 8:41 am

    If you’re rules are inside an .htaccess file, you can omit the leading slash when you match against a URI:

    RewriteRule ^([^/\.]+)/?$ /$1.php [L]
    

    Also note that a leading slash is included in the target (/$1.php), this makes sure /whatever/ gets rewritten to /whatever.php. When you redirect, if you are missing this leading slash, apache prepends the document root to it. Thus /whatever.php gets redirected to the document root C:/Sites/page/whatever/. Even if you include the leading slash, this will never work because you’re going to cause a redirect loop:

    1. Enter “http://www.example.com/whatever.php” in your address bar
    2. apache redirects you to “http://www.example.com/whatever/”
    3. apache gets the URI whatever/ and applies the first rule and the URI gets rewritten to /whatever.php
    4. The URI gets put through the rewrite engine again
    5. the URI /whatever.php matches the second rule and redirects the browser to “http://www.example.com/whatever/”
    6. repeat steps 3-5

    You need to add a condition that the actual request is for /whatever.php:

    RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /([^/\.]+)\.php
    RewriteRule ^ /%2/ [R,L]
    

    So altogether, you’ll have:

    RewriteEngine On
    RewriteRule ^([^/\.]+)/?$ /$1.php [L]
    RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /([^/\.]+)\.php
    RewriteRule ^ /%2/ [R,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my .htaccess: RewriteEngine On RewriteBase / RewriteRule ^index\.php$
I have follwing code in .htaccess file Options +FollowSymLinks RewriteEngine on RewriteRule tricks tricks.php?show=all
I have the following code in ://localhost/.htaccess... AddType application/x-httpd-php5 .css .js RewriteEngine on RewriteRule
I have the following .htaccess file Options +FollowSymLinks RewriteEngine on RewriteRule (.*)-pid-(.*)\.html$ product.php?n=$1&pid=$2 and
i have used the following code in .htaccess Options +FollowSymlinks RewriteEngine On RewriteBase /
I have the following rewrites in my .htaccess: Options +FollowSymLinks RewriteEngine On RewriteRule \.(css|jpe?g|gif|png)$
I have the following in a .htaccess file redirect 301 /page.php http://domain.com/page Which works
I have website which works fine and have following in the htaccess file RewriteEngine
i have the following .htaccess file for me web Options +FollowSymLinks RewriteEngine on RewriteRule
I have the following in my .htaccess currently- <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^go/([^/]*)/([0-9]+)/([0-9]+)/?$

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.