0

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.

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by MDGM
0

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?

0

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

0

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. ;)

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.