0

I'm using a search that create a query string for MySQL and show the result. The thing is that the query doesn't have the same length of variable each time a search is made.

I was wondering if in .htaccess it's possible to make a mod_rewrite depending on how much variable I throw at it.

Instead of having this in the URL

results.php?var1=something&var2=something&var3=.....

I get this

results/var1/something/var2/something/var3/something...

But remember that the numbers of vars can change depending on which checkboxes are checked by the user on the search form.

I hope it's clear if not I'll try to add more example.

1 Answer 1

1

Try this in your htaccess file in your document root:

RewriteEngine on
RewriteRule ^results/([^/]+)/([^/]+)(.*)$ /results/$3?$1=$2 [L,QSA]
RewriteRule ^results/$ /results.php [L,QSA,R]

The first rule will loop as long as there are /var/something pairs in the URI, and keeps appending them on the query string. When finally there are no more pairs left, the results/ gets rewritten to results.php.

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.