Jump to content

[SOLVED] Dynamic url handling at root level


daanoz

Recommended Posts

Hey ppl,

 

I've been working with dynamic urls on quite some projects now, and gotten quite used to it. To make clear what i do (because dynamic url handling might not be a good name), i'll give a short example :

 

Say, you have a page with a list of projects, and you want to offer visitors a info + download page to each project. To make a url look nice, we can do a simple trick.

 

so instead of:

- http://localhost/projects.php?id=1

- http://localhost/projects.php?id=22

- http://localhost/projects.php?id=34

- http://localhost/projects.php?id=4&ac=download

 

we get:

- http://localhost/projects/SearhApp

- http://localhost/projects/DownloadApplication

- http://localhost/projects/AnotherApp

- http://localhost/projects/SearchAppV2/Download

 

The trick behind this is renaming the "projects.php" to "projects" and making apache handling files with no extension as a php file (make sure you secure your application properly otherwise this might pose a security risk)

 

 

 

Right, my question...

 

I want to take this a step further, but i have no clue how. I want to remove the "projects" file as well. So I can have links like:

 

- http://localhost/SearhApp

- http://localhost/DownloadApplication

- http://localhost/AnotherApp

- http://localhost/SearchAppV2/Download

 

Without having actually having to create the files, i want to call the same php script everytime a url is requested. I think the same technique is used at www.php.net. Behind the domain you can put any php function your looking for, and you get redirected to the page you want (http://www.php.net/array_key_exists, http://www.php.net/fread, etc.)

 

So... how is it done?

 

Cheers

 

Daanoz

 

Link to comment
Share on other sites

Ok, i think i'm on the right track, but i'm missing something...

 

RewriteEngine On
RewriteRule /([a-z0-9]+) /testsite/httpdocs/projects/$1/ [NC,L]

 

results in:

[sat Mar 07 20:21:49 2009] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[sat Mar 07 20:21:49 2009] [debug] core.c(3046): [client 127.0.0.1] r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/projects/1/
[sat Mar 07 20:21:49 2009] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /testsite/httpdocs/test/1

 

whenever i call: http://localhost/testsite/httpdocs/test/1

 

my guess is that it also rewrites files that do exists (so i loops in a circle)

 

is there a good way to overcome this?

 

Cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.