Let's say I have a page called ABC.php. I want this file's name to change everytime someone goes to the page randomly according to a keywords.txt. Is it possible to do this with PHP, how, or should I use .htaccess? If so, how? The code I'm using right now is like the following; $pages = file("kwbase.txt"); $kw = array_rand($pages); $page = $pages[$kw]; header("Location: $page"); PHP: But this loads URLs, not keywords and also pretty slow. So I have to copy the page and rename it hundreds of times which would be a pain in the ass. I hope there is a way to make it easier
How many lines are in that file? I cant think of a faster way of doing it. You can combine the bottom 2 lines, but that's not going to make a huge difference.
I cannot imagine exactly what you are trying to accomplish. The biggest issue you face is that people access known URLs. This means that a link must exist to the page before someone would consider accessing it -- whether on another page, their favorites or in their imagination. Using .htaccess you can easily redirect queries for ABC.html to DEF.html, but the file needs to know how to do the redirect. Another option is to have .htaccess redirect all page queries to a script, which knows what to do, but that is still not the same as accessing ABC.html and getting XPF.html. Under this option, the page does not need to exist. It is constructed by the script as requested. .htaccess rewrite example: RewriteEngine on RewriteRule ^(.*)\.html$ /scripts/showstory.php?$1 [L] Code (markup): With this option you could create "linkify" a list of keywords as your pages are displayed to the visitor. If they click on the keyword, they are then transported to a page, which is constructed on the fly to provide whatever data you have available about that keyword, including whatever dynamic data you are also trying to generate.
About 55-60 pages I guess. Well, actually the following .htaccess was doing what I wanted, but I dunno how to set it up with my new script; AddHandler application/x-httpd-php html AddHandler application/x-httpd-php htmOptions RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*)-(.*)-(.*).html$ /search.php?q=$1+$2+$3 RewriteRule (.*)-(.*).html /search.php?q=$1+$2 RewriteRule (.*).html /search.php?q=$1 PHP: