Google Answers Logo
View Question
 
Q: Making RewriteRule's ( Answered,   0 Comments )
Question  
Subject: Making RewriteRule's
Category: Computers > Internet
Asked by: maperez8-ga
List Price: $15.00
Posted: 09 Jul 2006 11:46 PDT
Expires: 08 Aug 2006 11:46 PDT
Question ID: 744709
Hello!
I'm traying to make a rewrite rule to go from 

http://www.mysite.com/servlet/hficha?33918458,CI

My site is build with java, and doesn't need some par like par1=33918458,par2=CI

so... I'd like to rewrite from:
http://www.mysite.com/servlet/hficha?33918458,CI
to
http://www.mysite.com/servlet/hficha-33918458-CI.html

I'll glad if some bady can help me!

Best Regards
Alfredo
Answer  
Subject: Re: Making RewriteRule's
Answered By: sycophant-ga on 09 Jul 2006 19:21 PDT
 
Hi Alfredo, 

Assuming the structure of your URLs is always going to be:
(letters)(question mark)(numbers)(comma)(letters)

the following rewrite rule should work:

RewriteRule /servlet/([a-z]+)\?([0-9]+),([a-z]+)      /servlet/$1-$2-$3.html [NC]

- The above needs to be a single line, the space between the last )
and the / of the next section is typically a tab. This rule has been
constructed as case-insensitive, however to make it case sensitive,
simply remove the [NC] from the end and adjust the case of the [a-z]
accordinging. The rule is non-conditional and will apply to all
matching requests.

To work, mod_rewrite will need to be available and active, using the
'RewriteEngine on' directive.

If this doesn't work for you, please let me know, and possibly provide
some additional example URLs to refine the expression.

References:
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

Request for Answer Clarification by maperez8-ga on 10 Jul 2006 03:41 PDT
Hi ! Sycophant !
Thanks! for answer! but... Didn't work.. 

I Tried with:

hficha-14564147-DNID.html

And the error was:
javax.servlet.ServletException: Class `hficha-14564147-DNID.html' was not FOUND

(The rewrite rule doesn't rewriten to the format hficha?14564147,DNID

I don't know if with this clause that you send me.. It will became
from hficha-14564147-DNID.html to hficha?14564147,DNID

With Question mark and the comma (without .html)

AND

if it work only to hficha  (like I wish) or it will work to all servlets

hficha?14564147,DNID
messanges?14564147,DNID
sent?14564147,DNID

and so on...

Thanks ! very much !! for you clarifications !

Clarification of Answer by sycophant-ga on 11 Jul 2006 15:56 PDT
Hi Alfredo, 

I may have misunderstood the direction you wanted the rewrite to work.
The solution I have provided takes a web request for
'hficha?14564147,DNID' and makes it into 'hficha-14564147-DNID.html' -
It seems you are wanting to go the other way...

Try this rule instead:
RewriteRule /servlet/([a-z]+)-([0-9]+)-([a-z]+)(\.html)      /servlet/$1?$2,$3 [NC]

That should take any URL that matches:
[Letters][Hyphen][Numbers][Hyphen][Letters][".html"]
Then remove the .html, replace the first hyphen with a question mark,
and the second one with a comma. It is case insensitive (although case
will be retained).

Sorry for the confusion, I hope this is what you need.

Regards,
Sycophant-ga
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy