in reply to How do I create friendlier URLS?
Let's assume you have a CGI::Application module called My::App, and that your index.cgi looks like this:
#!/usr/bin/perl use My::App; My::App->new->run;
In this situation, you would need a new instance script for every new application module. CA::Dispatch takes that pain away by giving you the means to write a single dispatch script for all your appllications.
An example for your case might be:
If you save that script as index.cgi, your URL could become http://www.mydomain.com/index.cgi/loadPage?data=10.#!/usr/bin/perl use CGI::Application::Dispatch; CGI::Application::Dispatch->dispatch( prefix => 'My', default => 'App', );
By using more of CA::Dispatch's power, you can take that even further:
This dispatch script would be able to map the following URL: http:://www.mydomain.com/index.cgi/loadPage/10. The runmode is taken from the first part of the PATH_INFO (that's what the ":rm" indicates), and the page number is captured by the ":data?". You can access the page number in your runmode with $self->param('data').#!/usr/bin/perl use CGI::Application::Dispatch; CGI::Application::Dispatch->dispatch( prefix => 'My', table => [ '/:rm/:data?' => { app => 'App' }, ], );
The final step would be to get rid of the "index.cgi" part in your URL, but for that you do need to edit your web server config. I generally use mod_rewrite (as I do a lot of mappings), but a suitable <Location> section would suffice as well. The CGI::Application::Dispatch documentation has some examples for you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I create friendlier URLS?
by Raster Burn (Beadle) on Feb 22, 2007 at 16:07 UTC | |
by rhesa (Vicar) on Feb 22, 2007 at 18:44 UTC |