1

I have tried following code which works fine for me.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

using this, I can access the index.php by typing localhost/myProject/index only.

My question is, How can I take out .php from URL if I write localhost/myProject/index.php

I am doing this because I have created 100 webpages in my website and they are linked together, and now I do not want to show .php in browser and do not have time to change the code( due to short deadline :( ).

I am using LAMP stack and Apache's mod_rewrite is enabled.

4
  • You can redirect any .php addresses to non-.php addresses. But that means each request will have to occur twice and you'll have the .php address flash in the address bar for a second. You will have to change the code to link to non-.php addresses anyway. Bad planning which is costing you more time now. Tough luck. Commented Nov 27, 2012 at 12:18
  • Similar to stackoverflow.com/questions/9635524/… Commented Nov 27, 2012 at 12:35
  • Your question is similar to another question already asked here. There is a solution. stackoverflow.com/questions/1698464/… Commented Nov 27, 2012 at 12:35
  • 2
    Short deadlines are often the cause of the greatest amount of unnecessary work. Do yourself a favour, and take the time to do this the RIGHT way. If you need to go modify 100 web pages to point to non-.php files, then that's what you need to do. If they're separate web pages, perhaps you can come up with a fancy sed script for it, or a short-cut using your favourite text editor's find-and-replace function. If a deadline makes you do this wrong, then you've missed the deadline. Commented Nov 27, 2012 at 12:35

1 Answer 1

0
RewriteCond %{THE_REQUEST} \.php
RewriteRule ^(.*)\.php$ /$1 [R=301,L]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.