Hi all,

I have a site that has a dynamically generated page and looks like this:

www.example.com/articles.php?aid=1
www.example.com/articles.php?aid=2
www.example.com/articles.php?aid=3

The page has the article title and description stored in a database and printed in the page itself.

How do I go about changing the URL from this:

www.example.com/articles.php?aid=1

To this:

www.example.com/articles/how-to-fix-a-laptop

where the article description is stored in a database?

Thanks in advance.
Max.

Recommended Answers

All 4 Replies

Your links all give 404 errors.

Are you wanting to link to the page via method one, but have the url show in the window as the second example?

I know, the links above use the url www.example.com just for the sake of this thread.

The website currently has urls like this:

www.example.com/articles.php?aid=3

and I want to use .htaccess and apache's mod_rewrite to get information from the sites database and put that information in the url.

Let's say the article with primary key aid=3 (as shown in the url above) has the title "how to fix a laptop" in the database. I want to get that title from the database and re-write the url from what is above to the following:

www.example.com/articles/how-to-fix-a-laptop

I may be confusing this with another question, I thought I saw that you didn't want to use a hash file but that looks like it would be the way to go.

Use PHP to generate the hash file from the database and create RewriteRules to match them up.

$artinfo=popquery("select * from articles"); //popquery isn't a real function
$numarts=mysql_numrows($artinfo);
$hashf=fopen("myrewrites.txt","w+");
for (i$=0;$i<$numarts;$i++)
 {
 $aid=mysql_result($artinfo,$i,"id");
 $title=mysql_result($artinfo,$i,"title");
 $rulestring="RewriteRule ^/articles/$title /article.php?aid=$aid";
 fputs($hashf,$rulestring);
 }
 fclose($hashf);
 }

Something like that, maybe?

I think this is beyond my current knowledge base. ;)

Hey, sorry for the super late reply but iv been really busy.

In the end I just started over with the articles part of the site and am now using wordpress to manage all my articles and am using it's permalink function to get search-engine-friendly urls.

here:

http://www.effectivecounselling.co.uk/articles

I made a custom theme and integrated it into my site design, was actually very easy, for anybody elses reference theres a great tutorial here:

http://codex.wordpress.org/Integrating_WordPress_with_Your_Website

Thanks for your help, i might need this later anyway :)

Max.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.