Rasa Mohamed Rasa Mohamed - 3 years ago 91
PHP Question

HTACCESS for given url

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"

Answer Source

For this URL https://www.ex.com/hindu-bbb-10?pageno=2

You need to capture value from QUERY_STRING:

RewriteCond %{HTTP_HOST} ex.com$ [NC]
RewriteCond %{REQUEST_URI} (?:bbb|ggg)
RewriteCond %{QUERY_STRING} ^pageno=(\d+) [NC]
RewriteRule ^([^/]+)/?$ seo/index.php?cat=%1&&title=$1 [NC,QSA,L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download