3

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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great thank you very much, but how do I pass over that "adver1" string to a php script? and how do I pass the link from the database to the browser?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.