I need to create a clean url what i have is
localhost/tutorials/rewrite/read-news.php?url=the-news-today
and i want it to read
localhost/tutorials/rewrite/read-news/the-news-today
The page is called read-page.php and the content is generated from the database
The news.php contains the links to each news article and my link is wrote like this
<a href=“read-news.php?url=’ . $url . '”>’ . $title1. '</a>
and it is shown like this
localhost/tutorials/rewrite/read-news.php?url=the-news-today
My code to get the article is
$url = $_GET[‘url’];
$sql = “SELECT * FROM news WHERE url = ‘$url’”;
From looking at example I thought something like this in the htaccess would sort the problem, but it does not
RewriteRule ^read-news/(.*).php read-news.php?url=$1 [L]
PS. If you have a strict set of chracters the url field can contain, like only letters, digits and dashes, it’s better to code that instead of (.*), which is quite evil (although should be harmless here, unless you have URLs that are very similar)
Sorry that acctually didnt work
I was thinking maybe it was because i was using the url which stored within my database, the url field being the-news-today
I created a test page which a normal html layout and the following php code in the body
$url = $_GET[‘url’];
echo $url;
when i load tester.php nothing shows but if i change it to tester.php?url=hello
the word hello appears in the screen.
Going by your rewrite i should change read-news to tester and i should get this when i hit enter
localhost/tutorials/rewrite/tester/hello
As Rémon noted, specifying all the characters allowed (within a URI so, too, within the title) is HIGHLY advisable. However, be sure to make your url field UNIQUE. Note, though, that spaces are replaced with _'s for the link and converted back for access to the database.
Well whatever is wrong its not working for me. If anyone feels to be so kind my two files, htaccess and slq of my database is in the zipped link below. Iv have different people looking at it and they still cant figure it out. http://piercemcgeough.co.uk/rewrite-test.zip