Clarification on mod_rewrite within site


I am new to mod_rewrite and need some help on a few topics. I have been reading posts on this and trying out some of the suggestions. What I want to achieve is:

  1. My site is in php and all file extensions are therefore .php. I picked up some code from this forum on how to do this as follows:
RewriteCond %{THE_REQUEST} (.*)\\.html
RewriteRule ^(.*)\\.html $1.php [L]

RewriteCond %{THE_REQUEST} (.*)\\.php
RewriteRule ^(.*)\\.php $1.html [R=301,L]

This works ok, but a small issue is if I login with a username and password to part of the site, it does not do redirect to the correct page.

  1. I have links within the site that have an extra parameter eg:

Using some other code examples from this site I have the following:

RewriteRule ^property-([0-9]+)$ property.php?recid=$1 [L]

This code does not rewrite the url as I expect it as follows:

It shows the following:

However if I type into the address bar:

it does show the page.

  1. This point is to do with my understanding of the whole mod_rewrite configuration. If all the links in my site point to scripts with .php extensions, and I rewrite to html extensions, do I have to change all the links in my scripts to have html extensions.

Another question is that if I have extra parameters, eg. property.php?id=3 do I have to change the links within my scripts to point to property-3?

Apologies for my ignorance on this, but I have been searching for these answers, and what works for some people does not seem to work for me.

Thanks for any help you can give.


  1. Is the action of the login form set to a .php file? If so change it to .html (otherwise Apache will redirect the request to .php to .html and loose any POST data in the process)

  2. It’s up to you to change the URLs in the <a href> in your code; Apache won’t do that for you. All apache does is serve property.php?recid=id when /property-id is requested. No more, no less.

  3. yes and yes :slight_smile:

Thanks for getting back to me.

  1. Changed this within code and now works as expected.

  2. I think I understand better now. Changed this and now serves up correct address and page.

Thanks for your help. Very much appreciated. There is obviously lots to learn with this and more studied required from me.