Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod_rewrite rule

dynamic to static using mod_rewrite

1:41 pm on Jun 30, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 13, 2001
votes: 0


What would be my mod_rewrite code to achieve this

Present URL: [localhost...]

Required URL: [localhost...]

I have been trying with the below rule in httpd.conf but did not workout.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^ID\=([^&]+)$
RewriteRule ^$ /%1.htm [R=301,L]

I don't want any dynamic url inside me site but still serve the content from the mysql database.

Rightnow, News.php pulls the content from the mysql database and displays the various links as news.php?ID=1, news.php?ID=2 and so on...

I want the links inside the page news.php to be displayed as news1.htm and not news.php?ID=1

Is this possible? If yes how?

7:29 pm on July 1, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 12, 2005
votes: 0

For your .htaccess file, this is what you'll probably want:

RewriteEngine On
RewriteRule ^mysite/category/([a-zA-Z]+)([0-9]+)\.htm /mysite/category/$1.php?ID=$2

This will take any links from the new style, and make sure the web server treats them like the old. Note that this is case sensative, so if your webserver is case sensative as well, and you need news1.htm to go to News.php?ID=1, then you'll have to specify both the "news" and the "News" in that rule, ala:

RewriteRule ^mysite/category/news([0-9]+)\.htm /mysite/category/News.php?ID=$1

Then you need to change the links themselves as they appear on your site. That part you'll have to do in php, or do it manually on any static pages.