Simple rewrite URL with parameters not working

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 5
Joined: 14 Mar 2014, 10:22

Simple rewrite URL with parameters not working

14 Mar 2014, 10:27

Hello,

I have this url: http://localhost/bgh/Hogar_Personas_Cocina?ID=3 (Original)

And i'm trying to reach something like http://localhost/bgh/Cocina/3 (Rewrited)

RewriteRule ^Cocina/([0-9]+)/?$ Hogar_Personas_Cocina.aspx?ID=$1 [NC,L]

But when i browse the original, it's never rewrited.

I can say that the rewriting it is working because the original url should have the extension and by ISAPI is beeing hidded.

Thanks in advance!

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Simple rewrite URL with parameters not working

16 Mar 2014, 12:36

Hello,

You're doing the opposite to what you want. Try using:

Code: Select all
RewriteCond %{QUERY_STRING} ^ID=(\d+)$ [NC]
RewriteRule ^bgh/Hogar_Personas_Cocina /Cocina/%1? [NC,R=301,L]


Regards

User avatar
Posts: 5
Joined: 14 Mar 2014, 10:22

Re: Simple rewrite URL with parameters not working

17 Mar 2014, 10:34

Hi Andrew, thanks for your reply.

If use exactly as you said, the redirect isn't working.

The original is: http://localhost/bgh/Hogar_Personas_Cocina?ID=3

If i change your script to:
RewriteCond %{QUERY_STRING} ^ID=(\d+)$ [NC]
RewriteRule ^Hogar_Personas_Cocina Cocina/%1? [NC,R=301,L]

Removing de bgh/ and the strating / from Cocina, it redirects to http://localhost/bgh/Cocina/3, as i need, but a Page not found is beeing displayed.

If it helps, the original page, has the base tag.

Thanks for your help!
Regards

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Simple rewrite URL with parameters not working

17 Mar 2014, 22:55

It helps a lot. The base tag does it all.

Now you have a 301-redirect which only changes the URL in a browser. All you need is to add your rule to load the content from an old location.

Regards

User avatar
Posts: 5
Joined: 14 Mar 2014, 10:22

Re: Simple rewrite URL with parameters not working

18 Mar 2014, 17:34

Thanks, and that rule would be, how?

Thanks in advance

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Simple rewrite URL with parameters not working

19 Mar 2014, 08:01

The rule you provided. YOu need both:
Code: Select all
RewriteRule ^Cocina/([0-9]+)/?$ Hogar_Personas_Cocina.aspx?ID=$1 [NC,L]

RewriteCond %{QUERY_STRING} ^ID=(\d+)$ [NC]
RewriteRule ^Hogar_Personas_Cocina Cocina/%1? [NC,R=301,L]


Regards

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests