Forum Moderators: phranque
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.
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
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