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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:50:18+00:00 2026-05-22T12:50:18+00:00

I have the following htaccess file, which hides the php extension and forces all

  • 0

I have the following htaccess file, which hides the php extension and forces all URLs to use www:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteCond %{SCRIPT_FILENAME} !-d
   RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

For the first part the credit goes to this answer and the second one to this answer.

This works perfect in most cases, however there is one problem. When a user tries to go to http://example.com/foo (or instead of “foo”, whatever other page) it redirects to http://www.example.com/foo.php .

How can I make it redirect to http://www.example.com/foo , that is, whithout the .php?

  • 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-22T12:50:19+00:00Added an answer on May 22, 2026 at 12:50 pm

    You just need to change the order of your rules. First external redirect then the internal one. Have your code like this:

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    <IfModule mod_rewrite.c>
       Options +FollowSymLinks
       Options +Indexes
       RewriteEngine On
       RewriteCond %{SCRIPT_FILENAME} !-d
       RewriteRule ^([^\.]+)$ $1.php [NC,L]
    </IfModule>
    

    I have tested it and works fine on my end.

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

Sidebar

Related Questions

I currently have the following htaccess <IfModule mod_rewrite.c> # redirect all calls to index.php
I have the following rewrite in my .htaccess file which removes the .php extension
I have the following .htaccess file which works fine for say www.companyone.com: RewriteEngine On
I have the following in a .htaccess file redirect 301 /page.php http://domain.com/page Which works
So I have the following .htaccess file contents from my other project which is
In my .htaccess file I have defined following rule, RewriteRule t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA] The
In my .htaccess file i have the following re-write rule RewriteRule ^([a-z]*)$ work.php?album=$1 [L]
I have a page (ie www.mysite.com/products.php?catid=5 ) in which I use the $_REQUEST[catid'] to
I have website which works fine and have following in the htaccess file RewriteEngine
I have the following in my .htaccess file, which I do often for cleaner

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.