Forum Moderators: phranque

Message Too Old, No Replies

Getting permalinks info from mysql

permalink from database

         

Nt3N

11:02 am on Apr 11, 2007 (gmt 0)

10+ Year Member



hi all!

I'm trying to create a permalink system similar to that of wordpress.

my problem is this.

I want to redirect users who type
http://www.example.com/news-title-from-mysql.html
to
http://www.example.com/news.php?id=x

the problem is that the mod_rewrite rule works only if I tell the htaccess file how to rewrite URLs.

but in my case the new URL (permalink) should not be generated using the .php?id=x parameter, but using the page-title that is stored in a mysql database where news.php is going to query data out.

a bit difficult to explain, but if you use wordpress, u will surely know what I mean.

any ideas about how this can be done?

Thanks
/nico.

jdMorgan

12:39 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have access to the server config files, or can you get your host to add a 'custom' configuration directive (two lines)?

If so, you can define a RewriteMap to call a script (PERL) to access your database to look up the replacement URL/filepath. Once defined, you can use the map in .htaccess, but it must be defined in httpd.conf, conf.d, etc. -- at the server config level. This allows an internal rewrite to be used, so a redirect is not required.

Otherwise, you'd have to rewrite all permalink requests to a script, which would then look up the real URL and then redirect to it.

Jim

sdobney

5:42 pm on Apr 14, 2007 (gmt 0)

10+ Year Member



I'm going to be testing the following for the same problem without using Perl to access the DB, but this is before I've tried it. If there is an obvious flaw help would be appreciated.

To solve this you should be able to request the redirect to be sent to a generic reroute.php script. In the reroute.php script you would firstly do the database look up to find this_page_title is id=1234, then rather than redirect, use the PHP include statement to include the rewritten script with the necessary parameters. ie

$id=lookupID($page);
include "showpage.php?$id";

This runs the showpage.php?$id within the reroute.php without invoking the redirect. To the end user it just looks the same.

Saul