Zoolander
Zoolander

Reputation: 2363

MOD_REWRITE: How to rewrite /something to /something.html?

Can someone please tell me how to do this?

I tried using the following code but I don't see what I'm doing wrong?

<IfModule mod_rewrite.c>
  RewriteEngine On
</IfModule>

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

Upvotes: 0

Views: 122

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

You're missing a . in your regular expression:

This:

RewriteRule ^(*)$ $1.html

needs to be:

RewriteRule ^(.*)$ $1.html

You could also add this condition:

RewriteCond %{REQUEST_FILENAME}.html -f

to prevent 500 errors when someone requests a page that doesn't exist and properly return a 404.

Upvotes: 1

Related Questions