1

I have a domain with the following query string:

http://example.com/?taxo=question&cata=foo&catb=bar&catc=more 

My objective is to convert this query string after ?taxo= into a path based on the values for each parameter like so:

http://example.com/questions/cata/foo/catb/bar/catc/more/ 

Using .htaccess, this is what I've tried:

RewriteCond %{QUERY_STRING} RewriteRule ^taxo=(.*)&(.*)=(.*)&(.*)=(.*)&(.*)=(.*)$ $1/$2/$3/$4/$5/$6/$7 [L,R=301] 

However, that doesn't work for me. I'm trying to understand where I am going wrong with the RewriteRule line since the condition isn't being met.

1 Answer 1

1

You cannot match query string in a RewriteRule. You should use QUERY_STRING variable in a RewriteCond to match and capture value from query string:

RewriteEngine On RewriteCond %{QUERY_STRING} ^taxo=([^&]+)&([^=]+)=([^&]+)&([^=]+)=([^&]+)&([^=]+)=(.*)$ [NC] RewriteRule ^/?$ /%1/%2/%3/%4/%5/%6/%7? [L,R=301] 
  • Note that you will need to use %N syntax for back-reference of values captured in RewriteCond.
  • ? at the end of the target URI is to strip off previous query string.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.