Apache Server configuration support - mod_rewrite - unilimited amount of parameters

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > November 2004 > mod_rewrite - unilimited amount of parameters





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author mod_rewrite - unilimited amount of parameters
Maurice Lacroix

2004-11-16, 2:50 pm

I have a CMS-based website and want it to be indexed by search engines.
Every page of my site is called via page.php?pagID=x or
page.php?pagID=x&a=1&b=2, in case the script needs extra parameters.

I want my URL's to be something like

http://www.mydomain.com/pagID/2/a/111/b/222/c/333/ which should display
http://www.mydomain.com/page.php?pa...111&b=222&c=333

In the code I already have I can only use 3 parameters in my querystring,
but I want it to be unlimited. Any suggetions how I can do this?

Thanks a lot.


<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^(.+)/(.*)/(.+)/(.*)/(.+)/(.*)/$ /page.php?$1=$2&$3=$4&$5=$6 [L]
RewriteRule ^(.+)/(.*)/(.+)/(.*)/(.+)/(.*)$ /page.php?$1=$2&$3=$4&$5=$6 [L]
RewriteRule ^(.+)/(.*)/(.+)/(.*)/$ /page.php?$1=$2&$3=$4 [L]
RewriteRule ^(.+)/(.*)/(.+)/(.*)$ /page.php?$1=$2&$3=$4 [L]
RewriteRule ^(.+)/(.*)/$ /page.php?$1=$2 [L]
RewriteRule ^(.+)/(.*)$ /page.php?$1=$2 [L]

</IfModule>


lio

2004-11-17, 2:48 am

"Maurice Lacroix" <maurice@theothersite.nl> wrote in message news:<419a248f$0$774$3a628fcd@reader10.nntp.hccnet.nl>...
> I have a CMS-based website and want it to be indexed by search engines.
> Every page of my site is called via page.php?pagID=x or
> page.php?pagID=x&a=1&b=2, in case the script needs extra parameters.
>
> I want my URL's to be something like
>
> http://www.mydomain.com/pagID/2/a/111/b/222/c/333/ which should display
> http://www.mydomain.com/page.php?pa...111&b=222&c=333
>
> In the code I already have I can only use 3 parameters in my querystring,
> but I want it to be unlimited. Any suggetions how I can do this?
>
> Thanks a lot.
>
>
> <IfModule mod_rewrite.c>
> RewriteEngine on
>
> RewriteRule ^(.+)/(.*)/(.+)/(.*)/(.+)/(.*)/$ /page.php?$1=$2&$3=$4&$5=$6 [L]
> RewriteRule ^(.+)/(.*)/(.+)/(.*)/(.+)/(.*)$ /page.php?$1=$2&$3=$4&$5=$6 [L]
> RewriteRule ^(.+)/(.*)/(.+)/(.*)/$ /page.php?$1=$2&$3=$4 [L]
> RewriteRule ^(.+)/(.*)/(.+)/(.*)$ /page.php?$1=$2&$3=$4 [L]
> RewriteRule ^(.+)/(.*)/$ /page.php?$1=$2 [L]
> RewriteRule ^(.+)/(.*)$ /page.php?$1=$2 [L]
>
> </IfModule>


This is not tested sample - just guide (I have done similar thing once
but have not saved working sample)

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

But to my mind it would be better to parse REQUEST_URI in page.php. In
this case you would need one simple rule.

RewriteRule .* /page.php [QSA,L]

Best regards,
lio
Maurice Lacroix

2004-11-18, 7:49 am

I get a 500 Internal server error when I try your mod_rewrite code. Anyway,
thanks for the help.


"lio" <igor.lobanov@gmail.com> schreef in bericht
news:938bef97.0411170031.5961dabd@posting.google.com...
> "Maurice Lacroix" <maurice@theothersite.nl> wrote in message
> news:<419a248f$0$774$3a628fcd@reader10.nntp.hccnet.nl>...
>
> This is not tested sample - just guide (I have done similar thing once
> but have not saved working sample)
>
> RewriteRule ^([^/]*)/([^/]*)/(.+)$ /$3?$1=$2 [QSA]
> RewriteRule .* /page.php [QSA,L]
>
> But to my mind it would be better to parse REQUEST_URI in page.php. In
> this case you would need one simple rule.
>
> RewriteRule .* /page.php [QSA,L]
>
> Best regards,
> lio



Joachim Ring

2004-11-21, 5:50 pm

"Maurice Lacroix" <maurice@theothersite.nl> wrote in message news:<419c7608$0$774$3a628fcd@reader20.nntp.hccnet.nl>...
>
> I get a 500 Internal server error when I try your mod_rewrite code. Anyway,
> thanks for the help.


RewriteRule ^/([^/]*)/([^/]*)(.*)$ $3?$1=$2 [QSA,N]
RewriteRule ^$ /page.php [L]

works for me.

joachim
lio

2004-11-22, 7:50 am

"Maurice Lacroix" <maurice@theothersite.nl> wrote in message news:<419a248f$0$774$3a628fcd@reader10.nntp.hccnet.nl>...
> I have a CMS-based website and want it to be indexed by search engines.
> Every page of my site is called via page.php?pagID=x or
> page.php?pagID=x&a=1&b=2, in case the script needs extra parameters.
>
> I want my URL's to be something like
>
> http://www.mydomain.com/pagID/2/a/111/b/222/c/333/ which should display
> http://www.mydomain.com/page.php?pa...111&b=222&c=333
>
> In the code I already have I can only use 3 parameters in my querystring,
> but I want it to be unlimited. Any suggetions how I can do this?
>
> Thanks a lot.
>
>
> <IfModule mod_rewrite.c>
> RewriteEngine on
>
> RewriteRule ^(.+)/(.*)/(.+)/(.*)/(.+)/(.*)/$ /page.php?$1=$2&$3=$4&$5=$6 [L]
> RewriteRule ^(.+)/(.*)/(.+)/(.*)/(.+)/(.*)$ /page.php?$1=$2&$3=$4&$5=$6 [L]
> RewriteRule ^(.+)/(.*)/(.+)/(.*)/$ /page.php?$1=$2&$3=$4 [L]
> RewriteRule ^(.+)/(.*)/(.+)/(.*)$ /page.php?$1=$2&$3=$4 [L]
> RewriteRule ^(.+)/(.*)/$ /page.php?$1=$2 [L]
> RewriteRule ^(.+)/(.*)$ /page.php?$1=$2 [L]
>
> </IfModule>


This is not tested sample - just guide (I have done similar thing once
but have not saved working sample)

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

But to my mind it would be better to parse REQUEST_URI in page.php. In
this case you would need one simple rule.

RewriteRule .* /page.php [QSA,L]

Best regards,
lio
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com