mod_rewrite only one extension

Posted by Matthias Reisner on Server Fault See other posts from Server Fault or by Matthias Reisner
Published on 2012-06-02T15:03:46Z Indexed on 2012/06/02 16:43 UTC
Read the original article Hit count: 155

Filed under:
|
|
|

Currently I'm having the following htaccess content:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteRule ^(.*).html$ $1.php
 </IfModule>

I want to change the php extension to html. Now if I browse for localhost/xx.html I get the right content. BUT I also can use xx.php or xx to access the oontent! I only want to get the content if there is an html extension! How can I make this work???

Example: On the server I have the file foo.php. Now I want the user to type in foo.html in the browser to get the content of foo.php. But if he types foo.php there will be an error.

I already tried this

RewriteRule ^(.*)[^\.html]$ error.php
RewriteRule ^(.*)\.html$ $1.php

But that does not really work

Thanks!

© Server Fault or respective owner

Related posts about .htaccess

Related posts about mod-rewrite