Clean URL mod rewrite problem

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]

Can anyone help me out here please

Awwww, you’re so close! The only thing is you need to get rid of the .php in the first argument of the RewriteRule


RewriteRule ^read-news/(.*) read-news.php?url=$1 [L]

:slight_smile:

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 :frowning:
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

I am really confused

really confused,

This has been covered in the past … and it DOES work (http://wilderness-wally.com):

RewriteRule ^([-a-zA-Z0-9_&'!\\&#8230;]+)$ article.php?title=$1 [QSA,L]

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.

Regards,

DK

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

Please can someone be so kind to help

Ah, but the first part of the URL is the same as the basename of the file supposed to serve it light goes on in my head

Try adding Options -MultiViews to your .htaccess, that might solve it.

If it doesn’t, I’m out of ideas