kooshin
01-18-2005, 12:42 PM
Hello guys
I have a question. I have a data base(mysql) with a lot of information in many tables. It is a news system. The urls are generated like somesite.com/news.php?id=34 and then news is displayed according to that ID.
So now what I want to do is generate html pages on the fly from the data base like this forum http://designforums.com/forum/thread364.html . See the thread url is in HTML and shows well. How can I do such thing for my news thing or for any thing else just to reduce the load of mysql on the server?
I appreciate if you post some tutorials or some code which can do such thing . Thanks in advance for your help.
error404
01-18-2005, 01:18 PM
You want to look into mod_rewrite. It's really not too difficult if you have experience with REs, if not lots of people around here can help you.
You probably want a .htaccess something like this:
RewriteRule ^thread([0-9]+)\.html news.php?id=$1
kooshin
01-18-2005, 01:29 PM
All right I understand that part now . Thank you but do I have to add the url of every news id? That would be pain . I mean when you make a new thread in that forum or another forum which I saw it becomes an html file name extension instantly so how can this be done?
error404
01-18-2005, 02:57 PM
If you want to actually create the HTML files, you'd have to modify the source of the application you're using to do so.
mod_rewrite just tells Apache to redirect a request that matches the rule to a different URL you can construct from the original URL. It'll still call PHP as normal.
Vult-r
01-18-2005, 03:30 PM
Originally posted by kooshin
All right I understand that part now . Thank you but do I have to add the url of every news id? That would be pain . I mean when you make a new thread in that forum or another forum which I saw it becomes an html file name extension instantly so how can this be done?
i doubt there is someone adding every new url :P
it probbly generate 2 -or- more pages:
- the new thread page,
- and the (old) forum page where a new A HREF is placed on,
the thread numbers are probably tracked in a database or a file. so the system doesnt generate two the same pages by mistake
xelav
01-18-2005, 06:21 PM
just change link generation code - i think it's the best way
kooshin
01-20-2005, 09:54 AM
All right guys thank you for the answers :) xelav what do you mean by link generation code? am not getting may be you can post a code. Thank you all. I appreciate your help
Xenatino
01-20-2005, 05:09 PM
kooshin: You only need 1 RewriteRule for all the ID numbers.
Any URL that matches the expression thread([0-9]+)\.html will redirect to the file you specify. For example, thread123.html would display the content of news.php?id=123
kooshin
01-21-2005, 12:51 PM
So I only need to write RewriteRule ^thread([0-9]+)\.html news.php?id=$1
and anyother page which is generated dynamically will have a SEF url so that the mysql load is reduced? I have to admin am not getting :( .....