optional unordered parameters
7 posts
• Page 1 of 1
optional unordered parameters
hi, all,
my need is to rewrite the URL "/linea.asp?p=pppp&c=cccc&s=ssss&id=aaaa" to "/pppp/[/url]cccc/ssss/aaaa".
all 4 parameters have to be considered not compulsory and their order is not fixed.
can anybody please help me in defining one or more rules to achieve my goal?
thanks a lot!
d
my need is to rewrite the URL "/linea.asp?p=pppp&c=cccc&s=ssss&id=aaaa" to "/pppp/[/url]cccc/ssss/aaaa".
all 4 parameters have to be considered not compulsory and their order is not fixed.
can anybody please help me in defining one or more rules to achieve my goal?
thanks a lot!
d
Re: optional unordered parameters
sorry: "/linea.asp?p=pppp&c=cccc&s=ssss&id=aaaa" should become "/pppp/cccc/ssss/aaaa".
d
d
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: optional unordered parameters
Hello,
Well, there's no one magic-super rule for an issue like that... although we might come up with a set of rules.
So I'll give you an idea of what it could be for 1 parameter, then 2 parameters...
So depending on your URL architecture you may play a little with those rules and create some for 3 and 4 parameters. In case you need other combinations, create separate rule to foresee that situation.
While writing the above I've come up with another set of rules. The following must cover all combinations of 4 parameters:
regards
Andrew
Well, there's no one magic-super rule for an issue like that... although we might come up with a set of rules.
So I'll give you an idea of what it could be for 1 parameter, then 2 parameters...
- Code: Select all
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^p=([^&]+)$ [NC]
RewriteRule ^linea\.asp$ /%1 [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^p=([^&]+)&c=([^&]+)$ [NC]
RewriteRule ^linea\.asp$ /%1/%2 [NC,R=301,L]
So depending on your URL architecture you may play a little with those rules and create some for 3 and 4 parameters. In case you need other combinations, create separate rule to foresee that situation.
While writing the above I've come up with another set of rules. The following must cover all combinations of 4 parameters:
- Code: Select all
RewriteCond %{QUERY_STRING} p=([^&]+) [NC]
RewriteCond %{QUERY_STRING} c=([^&]+) [NC]
RewriteCond %{QUERY_STRING} s=([^&]+) [NC]
RewriteCond %{QUERY_STRING} a=([^&]+) [NC]
RewriteRule ^linea\.asp$ /%1/%2/%3/%4 [NC,R=301,L]
regards
Andrew
Re: optional unordered parameters
could you provide the exact/complete rule?
sorry for my poor skill...
thanks a lot.
d
sorry for my poor skill...
thanks a lot.
d
Re: optional unordered parameters
I've setup the rule but, as you can see, http://www.mgkvis.it/linea.asp?id=MG.K- ... L-PRODOTTO works fine while http://www.mgkvis.it/MG.K-Vis-Istant-En ... L-PRODOTTO doesn't...
do You have an idea of where is the mistake?
d
do You have an idea of where is the mistake?
d
Re: optional unordered parameters
probably I didn't explain correctly:
"http://www.mydomain.com/linea.asp?p=pppp&c=cccc&s=ssss&id=aaaa" works fine
"http://www.mydomain.com/pppp/cccc/ssss/aaaa" I would like to write this seo friendly formatted URL, remembering that all parameters are optional and unordered.
thanks a lot.
d
"http://www.mydomain.com/linea.asp?p=pppp&c=cccc&s=ssss&id=aaaa" works fine
"http://www.mydomain.com/pppp/cccc/ssss/aaaa" I would like to write this seo friendly formatted URL, remembering that all parameters are optional and unordered.
thanks a lot.
d
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: optional unordered parameters
Hello,
Firstly, to find a mistake we need to see how you adjusted the rule.
Secondly the rule I provided is for 301-redirect only. Creating of SEF-URLs usually consists of 2 parts: 301-redirect and rewrite. Redirect creates a pretty link in address bar and rewrite tells server what page we need to provide content from. This is a principle that I had to clarify before further explanation.
lets say you have couple pages that you can redirect using your scenario:
My point is that at this stage(after 301-redirect) there's no way for the server to know which values belong to 's', 'id' and 'd'. So we can only redirect, but there's no way to rewrite random number of parameters that are might have random order.
The solution - to change the scenario, like:
So parameters and values are staying together and we'd be able to write a rewrite rule.
Regards
Andrew
Firstly, to find a mistake we need to see how you adjusted the rule.
Secondly the rule I provided is for 301-redirect only. Creating of SEF-URLs usually consists of 2 parts: 301-redirect and rewrite. Redirect creates a pretty link in address bar and rewrite tells server what page we need to provide content from. This is a principle that I had to clarify before further explanation.
lets say you have couple pages that you can redirect using your scenario:
- Code: Select all
linea.asp?id=MG.K-Vis-Istant-Energy&s=PLUS-DEL-PRODOTTO ---> 301-redirect ---> MG.K-Vis-Istant-Energy/PLUS-DEL-PRODOTTO
linea.asp?id=MG.K-Vis-Istant-Energy&d=XYZ&s=PLUS-DEL-PRODOTTO ---> 301-redirect ---> MG.K-Vis-Istant-Energy/XYZ/PLUS-DEL-PRODOTTO
linea.asp?s=PLUS-DEL-PRODOTTO ---> 301-redirect ---> /PLUS-DEL-PRODOTTO
My point is that at this stage(after 301-redirect) there's no way for the server to know which values belong to 's', 'id' and 'd'. So we can only redirect, but there's no way to rewrite random number of parameters that are might have random order.
The solution - to change the scenario, like:
/linea.asp?id=XXXXX&c=YYYYY&d=ZZZZZZ should become id/XXXX/c/YYYYY/d/ZZZZZ
/linea.asp?d=ZZZZZZ&c=YYYYY should become /d/ZZZZZ/c/YYYYY
So parameters and values are staying together and we'd be able to write a rewrite rule.
Regards
Andrew
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 6 guests