homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod_rewrite rule
dynamic to static using mod_rewrite

10+ Year Member

Msg#: 3963 posted 1:41 pm on Jun 30, 2005 (gmt 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?



5+ Year Member

Msg#: 3963 posted 7:29 pm on Jul 1, 2005 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved