Reputation: 323
Here is what I want to do:
User comes to my site from www.mysite.com/advert1
(folder advert1 doesn't exist)
.htaccess
then removes www.mysite.com/
leaving just advert1
Store advert1
as a string in a cookie
Look for advert1
in a database then redirect the user to the URL specified in the database e.g mysite.com/news
.
Is this possible?
Upvotes: 3
Views: 1653
Reputation: 4492
You need to create the rule such where all requests are directed to a external script. Then the server script may look up the database, set cookies and redirect. The .htaccess can not do this by itself unless you write a extension for apache which is likely to be beyond the scope the application you need right now.
For now just redirect all requests to a script by
RewriteRule ^([A-Za-z0-9-])$ /advert.php?id=$1 [L]
you can use $ad_string = $_GET["id"];
to get the ad string in the $ad_string variable. Then you can make a connection to the database using mysql_connect()
and then run a sql query like "SELECT * FROM advert_table WHERE id = '" . mysql_real_escape_string($ad_string) . "'"
This should sort out your url for the query. then use a meta redirect
or a javascript redirect
or even a header 301 redirect.
Upvotes: 5