I have my site as localhost/tutorials/rewrite/news.php on this page are titles from news articles that are in my database. Each title is a link to read the article. The link is
'<a href="read-news.php?url=' . $url . '">' . $title1. '</a>'
The read-news.php page gets the url and uses it in an sql statement to get the article from the database
$url = $_GET['url'];
$sql = "SELECT * FROM news WHERE url = '$url'";
My link on the news.php page and the url on the read-news.php looks like this
localhost/tutorials/rewrite/read-news.php?url=the-news-today
How can i get it to look like
localhost/tutorials/rewrite/read-news/the-news-today.php
I have used the following htaccess code which by looking at other examples i thought should be enough to fix it
RewriteRule ^read-news/(.*).php /read-news.php?url=$1 [PT]
Any help please
edit: your RewriteRule needs some work too. try this:
RewriteRule ^read-news/(.*)\.php$ /read-news.php?url=$1 [PT](you need to use a “$” to signal the end of your rewrite and escape the . before “php” with a backslash)
Also, you should link to your pages how you want them displayed:
href="localhost/tutorials/rewrite/read-news/the-news-today.php"The .htaccess won’t magically change the urls for you.
Also if you want to be able to access your query string variables, i would add QSA to your flags:
[PT,QSA]that way you can still access your url variable with
$_GET['url'].