Please help me with this rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Please help me with this rewrite

Postby vinay.chilakamarri » Fri Jun 20, 2008 4:47 pm

Hi,

i am trying to map a REST like URL to a CGI script that I wrote, to pass in some params to that script. I would like to pass something like:

http://localhost:8080/service/agent/v1/couple/status/

and in the backstage I want to pass only v1 to the cgi script. Till about now I could accomplish this in my .htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteRule service/agent/([^/.]+)/couple/status/

/cgi-bin/printparams.pl?rpt_name=$1


But I get a response like 404 Not found:

Not Found

The requested URL /webservice/rm-agent/v1/monitor/server-status/ was not found on this server.

But the example in the sticky works perfectly well. I saw the example in the sticky but according to this, I should create sub directories for the URL exactly as it appears...

If we have a variable in between the URL, how can we build a structure like the one shown in the sticky??
vinay.chilakamarri
 
Posts: 10
Joined: Fri Jun 20, 2008 4:42 pm

Postby richardk » Sun Jun 22, 2008 2:27 pm

What part of the sticky?

You will probably need two rules
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^service/agent/([^/]+)/couple/status/?$ /cgi-bin/printparams.pl?rpt_name=$1 [QSA,L]
RewriteRule ^webservice/rm-agent/([^/]+)/monitor/server-status/?$ /cgi-bin/printparams.pl?rpt_name=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby vinay.chilakamarri » Sun Jun 22, 2008 2:48 pm

May be you're mod rewrite lord. That worked charm!. That [QSA,L] made the difference. I pasted the incorrect URL's 404 not found page by the way. Here is the sticky that I was talking about:

viewtopic.php?t=1443

I am truly inspired by this module.. I will try to gain some good expertise in this. Thanks for the help. Have a good one


richardk wrote:What part of the sticky?

You will probably need two rules
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^service/agent/([^/]+)/couple/status/?$ /cgi-bin/printparams.pl?rpt_name=$1 [QSA,L]
RewriteRule ^webservice/rm-agent/([^/]+)/monitor/server-status/?$ /cgi-bin/printparams.pl?rpt_name=$1 [QSA,L]
vinay.chilakamarri
 
Posts: 10
Joined: Fri Jun 20, 2008 4:42 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 99 guests

cron