Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am been plucking out my hairs since last few days trying to solve this problem:

I want to convert my urls from format

http://example.com/prodsearch/category/tag1-tag2-tag3-tag4

to

http://example.com/prodsearch/index.php?tag=tag1+tag2+tag3+tag4&cat=category

to start with I added following rules to my .htaccess

RewriteRule ^prodsearch/(.*)/(.*)-(.*)$ prodsearch/$1/$2+$3 [L]
RewriteCond %{REQUEST_URI} !^prodsearch/(.*?)/(.*)\-(.*)
RewriteRule ^prodsearch/(.*)/(.*)$ index.php?tag=$2&cat=$1 [R,QSA,L]

Here rule1 recursively replaces all '-' between tags by '+' and rule2 does the actual rewrite once there are no more '-' left between tags (checked by RewriteCond)

These rules actually work, but the problem is they redirect (with url change) to new url pattern, I don't want an explicit redirection. On removing 'R' flag from last rule, the whole thing stops working and I start getting 404 page in my wordpress install.

Can some one explain why this is happening and how to do this without explicit redirection.

Also I tried including these rules into wordpress, hoping when called by wordpress rules may work without redirection. I used following add_rewrite_rule() calls:

add_rewrite_rule('prodsearch/(.*)/(.*)-(.*)$','price-list/$1/$2+$3','top');
add_rewrite_rule('prodsearch/(.*)/(.*)$','index.php?tag=$matches[2]&cat=$matches[1]','top');

Now wordpress detects my first rule as external rule and flushes it to .htaccess file, this screws my execution order, now first rule 2 gets evaluated first(being part of internal wordpress rewrite rule set) and rule 1 gets executed later, hence again 404 page.

Is it possible to tell wordpress not to consider my first rule as a external rule and not to flush it to .htaccess, or to evaluate the external rewrite rule before internal wordpress rewrite rules.

Finally can anyone help me make this kind of rewrite work? Thanks a lot.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.