1

I have a URL-structure like this:

mypage.com/search/f7_987_Aprilia/f8_1234_Aprilia+RS+125
mypage.com/search/f7_987_Aprilia
mypage.com/search/f8_1234_Aprilia+RS+125

And I need them to route internally (without redirection) to the following structure:

mypage.com/search?&f[7]=987&f[8]=1234
mypage.com/search?&f[7]=987
mypage.com/search?&f[8]=1234

I have come this far: /(f\d+)(\d+).*/ This gives me the desired IDs in the first set. But how do I get the parameters separated by slashes? And how do I "convert" to the desired structure?

Is that possible with htaccess?

I hope there is a genius out there who can come up with the desired mod_rewrite regex

Thank you in advance!

1 Answer 1

1

You may use this code in site root .htaccess:

Options -MultiViews
RewriteEngine On

RewriteRule ^search/([a-z])(\d)_(\d+)_[^/]*/?$ search?&$1[$2]=$3 [L,QSA,NC]

RewriteRule ^search/([a-z])(\d)_(\d+)_[^/]*/([a-z])(\d)_(\d+)_[^/]*/([a-z])(\d)_(\d+)_[^/]*/?$ search?&$1[$2]=$3&$4[$5]=$6 [L,QSA,NC]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.