Rishi Ghosh
Rishi Ghosh

Reputation: 13

How can I have 2 rewrite rules on my .htaccess file

I currently have an .htaccess file that has one rewrite rule that removes .html however I cannot seem to be able to do the same thing with .php without messing up my whole website This is the code that I have in my .htaccess file.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.html -f

RewriteRule ^(.*)$ $1.html [NC,L]

Thanks

Upvotes: 1

Views: 45

Answers (1)

arkascha
arkascha

Reputation: 42885

Sure you can, why not?

Your version:

RewriteEngine on

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

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

Some lightly modified version:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^ %{REQUEST_URI}.html [END]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^ %{REQUEST_URI}.php [END]

You generally should switch off MultiViews when implementing such rules by the way.

Upvotes: 1

Related Questions