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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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] 

2 Comments

@Blazer, hey, since it all works, any chance you can click to accept the answer? :-)
@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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.