1

I don't know how to rewrite URLs of this type:

mywebsite/param1-val1-param2-val2-param3-val3-param4-val4.html 

that's really simple to do BUT my problem is that my parameters are variables like:

mywebsite/param1-val1-param3-val3-param4-val4.html 

or

mywebsite/param3-val3-param4-val4.html 

so, the number of parameters is not always the same. It can sometimes be just one, sometimes it can be 10 or more. It redirects to a search script which will grab the parameters through GET querystring.

What I want to do is to not write (on htaccess) a line for every link. The links are pretty simple in that form separated by a -(hyphen) sign.

1
  • If I understand you correctly, you want to rewrite, say, mywebsite/param1-val1-param3-val3-param4-val4.html to mywebsite/query.html?param1=val1&param3=val3&param4=val4? Commented Feb 13, 2013 at 14:15

1 Answer 1

1

Rather than rely on complex rewrite rules, I would suggest a simple rewrite rule and then modifying the code of your web application to do the hard part. Supporting this kind of variable parameters is not something that a rewrite rule is going to be very good at on its own.

I would use the following rewrite rule that intercepts any url that contains a hyphen separator and ends in .html

RewriteRule ^(.+[\-].+)\.html$ /query.html?params=$1

Then in your web application can get the parameters from the CGI parameter called params . They look like this now param1-val1-param3-val3-param4-val4. Your code should then split on the hyphens, and then put the parameters into a map. Most web frameworks support some way of adding to or overriding the request parameters. If so, you can do this without doing invasive modifications to the rest of your code.

Sign up to request clarification or add additional context in comments.

1 Comment

i thought about that... and I've already done something like that... thank you!

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.