Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod rewrite: infinte GET vars

Status
Not open for further replies.

MasterKaos

Programmer
Jan 17, 2004
107
GB
We are developing a PHP framework which will feature SEF urls. The requirement is that mod rewrite will convert url elements into GET vars. We want to keep this nice and arbitrary for easy re-factoring.

Here's the idea:

=

So each word between slashes, after the first, will populate PHP’s $_GET array with a numerically indexed array of parameters. The number of possible parameters needs to be arbitrary. Furthermore, after the SEF style of parameters, traditional get query strings can also be used, e.g.:


Currently we have a mod rewrite condition for each level of the url. e.g.:
Code:
RewriteRule index.php - [L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/javascript
RewriteRule ^(.[^/]*)[/]?$ /index.php?class=$1 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/javascript
RewriteRule ^(.[^/]*)/(.[^/]*)[/]?$ /index.php?class=$1&0=$2 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/javascript
RewriteRule ^(.[^/]*)/(.[^/]*)/(.[^/]*)[/]?$ /index.php?class=$1&0=$2&1=$3 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/javascript
RewriteRule ^(.[^/]*)/(.[^/]*)/(.[^/]*)/(.[^/]*)[/]?$ /index.php?class=$1&0=$2&1=$3&2=$4 [L,QSA]
I’m sure there must be a better way to do this, to write a single condition / rule which will support urls n levels deep.

Being a mod rewrite noob I have not been able to work out a way to do this.

Any suggestions?

Cheers!

----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top