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.

David
  • 8,340
  • 7
  • 49
  • 71
  • 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. – deceze Nov 27 '12 at 12:18
  • Similar to http://stackoverflow.com/questions/9635524/remove-php-extensions-with-htaccess-without-breaking-directoryindex – Robin Nov 27 '12 at 12:35
  • Your question is similar to another question already asked here. There is a solution. http://stackoverflow.com/questions/1698464/mod-rewrite-to-remove-php-but-still-serve-the-php-file – Neograph734 Nov 27 '12 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. – ghoti Nov 27 '12 at 12:35

1 Answers1

0
RewriteCond %{THE_REQUEST} \.php
RewriteRule ^(.*)\.php$ /$1 [R=301,L]
Gerben
  • 16,747
  • 6
  • 37
  • 56