J
J
jemanov2016-10-20 12:03:11
Apache HTTP Server
jemanov, 2016-10-20 12:03:11

How to get an arbitrary number of GET parameters via MOD_REWRITE?

There are links like:
www.site.ru/city123
www.site.ru/city123/type54/project1198
www.site.ru/project1198/type54/
In other words, the number of parameters may be arbitrary, or may not be at all.
Here is a code that helps to isolate only the first pair of letters + numbers

RewriteRule ^([a-z]*)([0-9]*)/*$ index.php?$1=$2%{QUERY_STRING}

At the output, I have: How in this case to get all GET parameters, if their number can be arbitrary or not at all?
$_GET[city] => 123

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2016-10-21
@shambler81

# 301 --- http://www.test.com/faq.html?faq=13&layout=bob => http://www.test2.com/faqs.html
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{QUERY_STRING} (^|&)faq=13($|&)
RewriteCond %{QUERY_STRING} (^|&)layout=bob($|&)
RewriteRule ^faq\.html$ http://www.test2.com/faqs.html? [L,R=301]

# 301 --- text/faq.html?faq=20 => helpdesk/kb.php
RewriteCond %{QUERY_STRING} (^|&)faq=20($|&)
RewriteRule ^text/faq\.html$ /helpdesk/kb.php? [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question