A
A
Artem Prokhorov2021-02-09 12:24:32
htaccess
Artem Prokhorov, 2021-02-09 12:24:32

How to make a redirect if the original URI has a GET parameter (that is, a question mark)?

Here is the redirect itself.

RewriteRule ^\?p=(\d+)$ index\.php/$1 [NC,L,R]

If you write a question mark in the second rewrite parameter, then there are no problems with this, it does not give errors and the GET parameter is passed, for example

RewriteRule ^ (\d+)$ index\.php/\?p=$1 [NC,L,R] (this is how it works, but I need it the other way around)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-02-09
@kotcich

How mod_rewrite actually works .
Only the path to the requested file is passed to RewriteRule, and GET parameters should be looked for in %{QUERY_STRING}.

RewriteCond %{QUERY_STRING} (?:^|&)p=(\d+)(?:$|&)
RewriteRule ^ /index.php/%1? [L,R]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question