S
S
Sergey2019-12-05 15:29:48
htaccess
Sergey, 2019-12-05 15:29:48

How can I fix the cnc rule in htaccess?

Good afternoon.
There is a line: ?page=product&item=888
In the htaccess file I write a rule for it:
RewriteEngine On
RewriteRule ^product/(.*)/$ index.php?page=product&item=$2 [L]
The rule does not work. Tell me what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2019-12-05
@shambler81

give me the two lines that have become, because you made a mistake at the very beginning
GET is not part of the line, why are you trying to select it?

# 301 --- http://www.test.com/product/333 => http://www.test.com/index.php?page=product&item=888
RewriteRule ^product/333$ /index.php\?page=product&item=888 [L,R=301]

But if you have a get in the original line, then so
# 301 --- http://www.test.com/?page=333 => http://www.test.com/index.php?page=product&item=888
RewriteCond %{QUERY_STRING} (^|&)page\=333($|&)
RewriteRule ^$ /index.php?page=product&item=888 [L,R=301]

All that remains is to replace 333 with a regular expression and group it
# 301 --- http://www.test.com/?page=333 => http://www.test.com/index.php?page=product&item=888
RewriteCond %{QUERY_STRING} (^|&)page\=([0-9]{1,})($|&)
RewriteRule ^$ /index.php\?page=product&item=%2 [L,R=301]

where %2 is analogous to $2 but from RewriteCond
But usually php does this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question