Z
Z
zapatronen2017-08-15 00:07:43
URL Handling
zapatronen, 2017-08-15 00:07:43

How to get rid of duplicate link with GET parameter?

Hello, I am without preludes.
The old links look like:
site.com/product.php?article=PP620
Added one more parameter to the product name link so that the keywords appear in the link and get the following:
site.com/product.php?article=PP620&name=arduino-uno
After converting a link to CNC with two parameters I get:
site.com/PP620/arduino-uno.html
But there are still two types of links to the same product, namely: a link with one parameter and a link converted to CNC.
How can I redirect from a link with one GET to a link with two GET ?
Here is my code which converts and redirects without infinite redirect. Help with a hint, modify the code or do you need to add a condition?

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^article=([^&]*)&name=([^&]*)
RewriteRule ^product\.php$ /%1/%2.html? [R=301,L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /product.php?article=$1&name=$2 [L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
roxik, 2017-08-15
@roxik

It is already in the site code to make a redirect.

V
Viktor Taran, 2017-08-17
@shambler81

If I were you, I would separate the Queri separately
so that it will be possible to work with the conditions.

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} (^)article\=(.+[^&])$
RewriteCond %{QUERY_STRING} (^|&)name=($|&)
RewriteRule ^product\.php$ /%1/%2.html? [R=301,L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /product.php\?article=$1&name=$2 [L]

Don't forget to escape special characters
\=
\?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question