Forum Moderators: phranque
[edited by: not2easy at 4:24 pm (utc) on Jan 10, 2020]
[edit reason] URL readability [/edit]
I can't figure out why products_id 12 and 1282 both redirect to ... xyz
The query string is just "product_id". Is there a better way to do it?
# Only matches "products_id=1408" exactly
RewriteCond %{QUERY_STRING} =products_id=1408
:
# Only matches "products_id=1282" exactly
RewriteCond %{QUERY_STRING} =products_id=1282
:
RewriteCond %{QUERY_STRING} =products_id=12
:
RewriteCond %{QUERY_STRING} products_id=\d
RewriteRule ^ /allredirects.php [L]
and then let /allredirects.php do the lookup and issue the redirect. Keep the rule in the same place in htaccess--that is, among the specific redirects with R=301 flag, not down below with the rewrites. As written, this means the RewriteCond will be evaluated on all requests ever: interior pages, ErrorDocuments, supporting files, everything. This seems awfully wasteful. Surely the "products_id=blahblah" parameter will only be found attached to specific URLs, either within some directory, or with paths in some particular format? Those should be given in the body of the rule.
Here is the full url of a product in the old store:
www.domain.com/catalog/index.php?main_page=product_info&products_id=12
RewriteCond %{QUERY_STRING} \bproducts_id=1408\b
RewriteRule ^catalog/index\.php$ https://shop.xyz.com/collections/products/mno? [L,R=301]
Here is the full url of a product in the old store:
www.domain.com/catalog/index.php?main_page=product_info&products_id=12
Although, rather confusingly, you stated that "The query string is just 'product_id'" - that's not what it looks like in the above URL?
Instead of the end-of-string anchor $ I'd use the word-boundary anchor \b. That way, if there happen to be other components to the query string, it will still work.
\bproducts_id=1408\b