In my website, I am trying to rewrite few of my URLs as bellow:
This URL
http://example.com/news.php?newstype=newsletter&newsid=1123&newstitle=my news title
int to:
http://example.com/newsletter/1123/my news title
My rewrite rule in .htaccess
looks like as shown below:
RewriteEngine On
Options FollowSymlinks
RewriteBase /
RewriteRule ^(.*)/(.*)/(.*)/?$ news.php?newstype=$1&newsid=$2&newstitle=$3 [L,QSA,NC,B]
My <a>
tag is looks this:
$seoUrl = "$urlNewsType/$newsid/$urlNewsTitle/";
$seoUrl = urldecode($seoUrl);
$seoUrl = html_escape($seoUrl, 'UTF-8');
<a href="$seoUrl">Read More</a>
These every things are working for me. But my question is, I need to get these query string parameters separately from URL into PHP. Problem is I can't get these prameters as I do usually.
In php, This is the output of:
echo '<pre>',print_r($_GET).'</pre>';
Array
(
[newstype] => news/1114
[newsid] => Presentation: Heath Day in 2018
[newstitle] =>
)
Can anybody tell me, what is the wrong which I have done in this regard?
CodePudding user response:
The regex pattern (.*)
is lazy. It matches the full requested path. Try ([^/] )
instead :
RewriteRule ^([^/] )/([^/] )/([^/] )/?$ news.php?newstype=$1&newsid=$2&newstitle=$3 [L,QSA,NC,B]