I’m trying to write REWRITERULE for NEW url.
old url : https://www.ex.com/hindu-bbb-10/2
old htaccess:
RewriteCond %{HTTP_HOST} ex.com$ [NC]
RewriteCond %{REQUEST_URI} (bbb|ggg)
RewriteRule ^(.+?)/(.+?)(/?)$ seo/index.php?cat=$2&title=$1 [NC,L]
by using above htaccess I could get values from REQUEST
like as folllows
[cat] => 2 [title] => hindu-bbb-10
I tried lot and one is as follows
NEW URL : https://www.ex.com/hindu-bbb-10?pageno=2
NEW htaccess:
RewriteCond %{HTTP_HOST} ex.com$ [NC]
RewriteCond %{REQUEST_URI} (bbb|ggg)
RewriteRule ^(.+?)/(.+?)(.+?)$ seo/index.php?cat=$2?pageno=$1 [NC,L]
And getting result like this [cat] => hindu-bbb-10
I can’t get values like [cat] => 2 [title] => hindu-bbb-10
which is form old url.
How to get values like [cat] => 2 [title] => hindu-bbb-10
using new url “https://www.ex.com/hindu-bbb-10?pageno=2“
2
Answers
If you’re wanting the result to be:
Then you will have to change your rewrite rule to accomodate that. You have got the right idea of doing it but when you want certain variables to be used you can use
$2
and$1
as you have done.The rewrite rule should be something along the lines of
If you would like to change cat to
pageno=2
I would create an array by using the variables you have managed to get. E.g.This should change your url to how you would like it. If this doesn’t work then I would advice you to read the
.htaccess
documentation:https://httpd.apache.org/docs/current/howto/htaccess.html
For this URL
https://www.ex.com/hindu-bbb-10?pageno=2
You need to capture value from
QUERY_STRING
: