-2

I am new in php web development, I am trying this codes to hide .php extension from My website URL, through .htaccess file but it can't work and showing "Server Error"

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>

Please help me on this issue.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
khizar067
  • 37
  • 2
  • 6
  • Possible duplicate of http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess – Amir May 20 '13 at 09:32
  • In addition to this being a dupe - a simple google search would have answered this. I find it astounding that people think its easier to post a question here asking for help than it is to type a generic search term into google. http://tinyurl.com/lweo7ge - the first two search results are from this very website. – Dutchie432 May 20 '13 at 10:58

3 Answers3

1

You would have found this link if you did even a basic google search.

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L, QSA]
Community
  • 1
  • 1
Dutchie432
  • 28,798
  • 20
  • 92
  • 109
0
RewriteEngine On

    # Unless directory, remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]

    # Redirect external .php requests to extensionless url
    RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]

    # Resolve .php file for extensionless php urls
    RewriteRule ^([^/.]+)$ $1.php [L]
underscore
  • 6,495
  • 6
  • 39
  • 78
0
 <IfModule mod_rewrite.c>
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
Sudz
  • 4,268
  • 2
  • 17
  • 26
  • Will this work? It seems to me that this will just rewrite from the same url entered. I don't see any PHP subbing going on. – Dutchie432 May 20 '13 at 09:56
  • Yes, it will. $1 will take care of extension – Sudz May 20 '13 at 10:02
  • Im not sure I understand. `$1` represents whatever is in the URL. if the URL is `/test` - at what point does the `.php` get appended? Wouldn't it just rewrite from `/test` also? Im not trying to be a a wise guy - I just really like the simplicity and am curious how it works. – Dutchie432 May 20 '13 at 10:56