4

What lines should I add to remove both .html and .php extensions from my site?

I use this for just the .html part:

RewriteEngine on

RewriteBase /
RewriteCond %{http://jobler.ro/} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://jobler.ro/$1 [R=301,L]

but I need for both file type extensions to be hidden from the same domain.

cnst
  • 25,870
  • 6
  • 90
  • 122
Blazer
  • 306
  • 4
  • 16

2 Answers2

6

I know its late to answer but I giving it since it can be useful to someone :)

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

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

This will remove both php and html extension from your files and works perfectly.

Atai Rabby
  • 73
  • 1
  • 8
4

You would want to test whether the file with .html or .php exists, and then redirect to such file if so.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$  $1.html [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$  $1.php [L]

RewriteCond %{REQUEST_URI} \.((html)|(php))$
RewriteRule ^(.*)\.([^.]+)$  $1 [R,L]
cnst
  • 25,870
  • 6
  • 90
  • 122
  • @Blazer, hey, since it all works, any chance you can click to accept the answer? :-) – cnst Feb 02 '16 at 23:17
  • @Blazer, since this works perfectly well, any chance you can click the accept button, so that both you and me get the points for the hard work? thanks! – cnst Jul 03 '16 at 06:22