If thats the case, I would make 1000 pages if I have 1000 records, so this would not be the solution. What I want is that when the user request view_lyrics.php?key=100, it must have something a script into it that would create a static 100.html in /lyrics/ subdirectory and then redirect the user to that page or instead of view_lyrics.php?key=100 I like it to be view_lyrics.html/lyrics/100.
OK. This is what I've tried. I almost spending this more than 10 hours but still I got no solution. The file below is what I have tried on making the .htaccess file. I tried each option one by one.
#File: .htaccess
#Redirecting users to a search engine friendly URL
#This will not work, 500 Internal Server error occur
RewriteEngine On
RewriteBase /PHPLyrics/
RewriteRule ^index\.html$ index.php [T=application/x-httpd-php]
#This one also won't work, Internal server error
RewriteEngine On
RewriteRule ^index\.php$ view_lyrics.php?key=3
#This one also won't work, Internal server error
RewriteEngine On
RewriteRule ^key/1/$ view_lyrics.php?key=1
#This one also won't work, Internal server error
RewriteEngine On
RewriteRule ^?key=3$ [url]http://localhost/phplyrics/key_3.html[/url] [R]
#In case all I try won't work, I'll go for this
#AddType application/x-httpd-php .php .html
The last option is the only working method but I think I won't go for this because of link.html?id=$id where there's still a question mark. I would not go also for mod_rewrite because I don't have access to the configuration file in my host.
The last thing I do below is really what I'm looking for but it won't work:
toplyrics.php
<?php
require("config.php");
$lyricsquery = "SELECT LyricsId, Title, Hits FROM lyrics ORDER BY Hits DESC LIMIT 0, 10";
$lyricsquery_result = mysql_query($lyricsquery, $ServerConnect);
while($lyricsrow = mysql_fetch_array($lyricsquery_result))
{
$key = $lyricsrow['LyricsId'];
$title = $lyricsrow['Title'];
echo [B]"<a href='cache/view_lyrics/key_$key.html' [/B]title='View $title lyrics.' target='_parent'>$title</a><br>";
}
mysql_free_result($lyricsquery_result);
mysql_close($ServerConnect);
?>
and the cache.php file
<?php
$cache_file = $REQUEST_URI;
$maker_URL = str_replace ( "/cache/" , "/" , $cache_file );
$maker_URL = str_replace ( ".html" , "" , $maker_URL );
$last_slash = strrpos ( $maker_URL , "/" );
// find out the creating script's name
// and make sure it exists.
$script = substr ( $maker_URL , 0 , $last_slash ) . ".php";
$find = $DOCUMENT_ROOT . $script;
if ( !file_exists ( $find )) {
// if the file does not exist, show a
// File Not Found error -
echo ("Couldn't find $REQUEST_URI");
// you can put a nice page here...
exit;
// but don't forget to exit !
}
// now parse the query string
// here, "_" means "=" and "__" means "&"
// These rules are just personal preferences
$query_str = "?" . substr ( $maker_URL , $last_slash+1 );
$query_str = str_replace ( "__" , "&" , $query_str );
$query_str = str_replace ( "_" , "=" , $query_str );
// and now create the full maker_URL
$maker_URL = "http://" . $HTTP_HOST . $script . $query_str;
// open the maker script and read its output
$read = fopen ( $maker_URL , "r" );
if ( !$read ) {
echo ( "Could not open $maker_URL" );
exit;
}
$HTML_output = "";
// read the HTML output while displaying it
while ($line = fgets ( $read , 256 )) {
$HTML_output.= $line;
echo $line;
}
fclose ( $read );
// finally, save the HTML output
// in a cache file.
$write = fopen ( $DOCUMENT_ROOT . $cache_file , "w" );
if ( !$write ) {
// you might not have permission
// to write in that directory.
echo ( "could not open $writefile for writing" );
exit;
}
// lock the write file and
// write all the HTML into it
if ( !flock ( $write , LOCK_EX + LOCK_NB )) {
// for PHP version < 4.0.1
// change LOCK_EX to 2
echo ( "could not lock $writefile" );
exit;
}
fwrite ( $write , $HTML_output , strlen ( $HTML_output ) );
flock ( $write , LOCK_UN );
// release lock. For PHP version < 4.0.1
// change LOCK_UN to 3
fclose ( $write );
?>
I got no error message on this. It just don't generate a file. I hope you can still help me on this problem.
Thanks.