Reputation: 21
I am trying to re-write:
news.php?q=Contact+form+with+attachment
to look like:
news/Contact+form+with+attachment
my link looks like this
<a href="news/'.urlencode($row['title']).'">
and appears like this
http://localhost/untitled/public_html/news/Contact+form+with+attachment
in my news.php file
, I have this code at the top
<?php $id = urldecode($_GET['q'])
$id = preg_replace('#[^0-9a-zA-Z]#i','',$id);
$query = "SELECT * FROM news WHERE title = :id" ?>;
then in my .htaccess I wrote this
RewriteRule ^news/([0-9a-zA-Z_%+-]+) news.php?q=$1 [NC,L]
But when I click on the link it doesn't work it shows an empty/blank page please help thanks
Upvotes: 2
Views: 58
Reputation: 154
The first variable $id
wasn't correctly closed. Maybe the page is returning an empty or blank space because it's a fatal error. Change your code for this:
<?php
$id = urldecode($_GET['q']);
$id = preg_replace('#[^0-9a-zA-Z]#i','',$id);
$query = "SELECT * FROM news WHERE title = :id";
?>
Sorry for my english.
Upvotes: 1
Reputation: 41051
it looks like you might be getting a white blank page because of a missing ;
in your php at the end of this line <?php $id = urldecode($_GET['q'])
I don't know if that's your whole problem, but start by adding that like this:
<?php
$id = urldecode($_GET['q']);
$id = preg_replace('#[^0-9a-zA-Z]#i','',$id);
$query = "SELECT * FROM news WHERE title = :id" ?>;
Upvotes: 1