Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:23:02+00:00 2026-06-17T05:23:02+00:00

I have a URL which may contain three parameters: ?category=computers &subcategory=laptops &product=dell-inspiron-15 I need

  • 0

I have a URL which may contain three parameters:

  1. ?category=computers
  2. &subcategory=laptops
  3. &product=dell-inspiron-15

I need 301 redirect this URL to its friendly version:

http://store.example.com/computers/laptops/dell-inspiron-15/

I have this but cannot make it to work if the query string parameters are in any other order:

RewriteCond %{QUERY_STRING} ^category=(\w+)&subcategory=(\w+)&product=(\w+) [NC]
RewriteRule ^index\.php$ http://store.example.com/%1/%2/%3/? [R,L]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:23:04+00:00Added an answer on June 17, 2026 at 5:23 am

    You can achieve this with multiple steps, by detecting one parameter and then forwarding to the next step and then redirecting to the final destination

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^category=([^&]+) [NC,OR]
    RewriteCond %{QUERY_STRING} &category=([^&]+) [NC]
    RewriteRule ^index\.php$ $0/%1
    
    RewriteCond %{QUERY_STRING} ^subcategory=([^&]+) [NC,OR]
    RewriteCond %{QUERY_STRING} &subcategory=([^&]+) [NC]
    RewriteRule ^index\.php/[^/]+$ $0/%1
    
    RewriteCond %{QUERY_STRING} ^product=([^&]+) [NC,OR]
    RewriteCond %{QUERY_STRING} &product=([^&]+) [NC]
    RewriteRule ^index\.php/([^/]+/[^/]+)$ http://store.example.com/$1/%1/? [R,L]
    

    To avoid the OR and double condition, you can use

    RewriteCond %{QUERY_STRING} (?:^|&)category=([^&]+) [NC]
    

    as @TrueBlue suggested.

    Another approach is to prefix the TestString QUERY_STRING with an ampersand &, and check always

    RewriteCond &%{QUERY_STRING} &category=([^&]+) [NC]
    

    This technique (prefixing the TestString) can also be used to carry forward already found parameters to the next RewriteCond. This lets us simplify the three rules to just one

    RewriteCond &%{QUERY_STRING} &category=([^&]+) [NC]
    RewriteCond %1!&%{QUERY_STRING} (.+)!.*&subcategory=([^&]+) [NC]
    RewriteCond %1/%2!&%{QUERY_STRING} (.+)!.*&product=([^&]+) [NC]
    RewriteRule ^index\.php$ http://store.example.com/%1/%2/? [R,L]
    

    The ! is only used to separate the already found and reordered parameters from the QUERY_STRING.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a url which have a response in Json lon=-0.1275&pg=0 I parsed the
I have a url which has some get variables in it like: domain.com/recover?email=my@email.com&token=abc123 inside
I have the following URL which links to the product page of a Mac
I want to make customer route for url which have parameters. <a href='javascript:void(0)' onclick=window.location='<?php
I have a URL which can be any of the following formats: http://example.com https://example.com
I have a url which could be www.website.com/order/?pg3=2 or www.website.com/orderstatus/?pg2= There could be several
Hi have this URL string which I need to extract possibly using regex but
In the sitemap file, I have sitemap Node URL which have more than 1
I have a perl script URL which gives me a ZIP file, it processes
I have a json feed from this URL which contains 20 fields and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.