Topic: Hide .php Extentions in .htaccess

I want to add several independent .php pages to the root folder of my MONSTRA CMS Installation with the file extension to be removed on the file e.g.

www.domain.com/page.php = www.domain.com/page
and
www.domain.com/subfolder/page.php = www.domain.com/subfolder/page

So if someone types in: www.domain.com/page.php they are redirected to: www.domain.com/page

I have included in the root .htaccess some apache rewrite rules, but I think these rules conflict with the original rules in the Monstra .htaccess file because i get the following results:

  • www.domain.com/page works smile

  • www.domain.com/page.php DOES NOT REDIRECT TO www.domain.com/page sad

  • if you add a trailing slash: www.domain.com/page/ i get a 500 internal server error response. sad

I would also like the trailing slash (www.domain.com/page/) to be redirected to (www.domain.com/page)

I am struggling to get my head around to understanding apache .htaccess, as I am newby to anything web development related and just starting to get my hands dirty...

If someone could help me by providing the correct .htaccess adapted from on MONSTRA .htaccess I would be really grateful.

Below is the code I used in my .htaccess file:

#
# Monstra CMS :: php & apache settings 
#
# Set default charset utf-8
AddDefaultCharset UTF-8
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
    php_flag magic_quotes_gpc                 off
    php_flag magic_quotes_sybase              off
    php_flag register_globals                 off
</IfModule>
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
## hide .php or .html extension
# To externally redirect foo.php ot foo.html to foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.(php|html) [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
# Setting rewrite rules.
<IfModule mod_rewrite.c>
    RewriteEngine on
    # Update code bellow for SEO improvements 
    # RewriteCond %{HTTP_HOST} ^www.example.org [NC]
     # RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]
    RewriteBase /mydomain.com/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [QSA,L]
    # Update code bellow for SEO improvements 
    # Redirect 301 /home http://example.org/
</IfModule>

Re: Hide .php Extentions in .htaccess

Hi

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]+$ 
RewriteRule ^(.+?)/*$ $1.php [L,QSA]