This forum has been moved here:
Helicon Tech Community Forum

Helicon Ape (Forum Locked Forum Locked)
 Helicon Tech : Helicon Ape
Subject Topic: URI to Querystring
Author
Message |
ApeNut
Newbie


Joined: 05 June 2011
Location: United States
Posts: 3
Posted: 09 June 2011 at 8:33pm

Greetings,

I have a question that's probably been asked many times but I can't get it work.  I want to transform this:

http://www.site.com/ca/san+francisco

to this

http://www.site.com/default.aspx?location=san+francisco,ca

Any help is apperciated.  Also, if you can teach how to fish..later on, I want to be able to do this:

http://www.site.com/ca/san+francisco/coffee

to this:

http://www.site.com/default.aspx?location=san+francisco,ca&keywords=coffee

so how do you get the N matches for /a/b/c/d/e/.../n?  I know we have to loop (LP) ...but would one regex work if the number of subdirectories varies in number - for example, site.com/a/b/c/d  v. site.com/a/b/c?

Any example is appreciated.  Thanks in advance

 

Back to Top
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 10 June 2011 at 5:07am

Hello,

in your case LP flag won't help. But I'll give you the rules for the two cases above and I guess you'll be able to write more by analogy:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ default.aspx?location=$2,$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ default.aspx?location=$2,$1&keywords=$3 [NC,L]

Please notice that on IIS7 you can have issues with "+" sign in URLs. See this article for solution:
http://www.helicontech.com/articles/plus-sign-in-iis7/

__________________
Regards,
Anton
Back to Top
 
ApeNut
Newbie


Joined: 05 June 2011
Location: United States
Posts: 3
Posted: 10 June 2011 at 12:39pm

Thank you Anton.  The issue that I've been facing is that when I use your rule above or my own (something like ^/?(..)/(.+)/?$), and send a request like

www.site.com/ca/san+francisco

The default.aspx page loads fine and rewriting takes place but all other files like css, images and js scripts in the page now have "/ca/" as their base URL instead of the root.  Of coruse, those resources are not found having /ca/ in their path and thus the page is broken.

I tried to put "RewriteBase /" both before and after each rule but that doesn't help.  So if I only get three wishes, I would like to spend my second wish and ask you how to fix that because I have no idea and I tried just about everything

Thanks again fellows.  Good stuff!

Back to Top
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 14 June 2011 at 1:38am

Do you only have one rule of your own? This one: ^/?(..)/(.+)/?$) ?
Please consider putting these conditions before your rule as well:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

__________________
Regards,
Anton
Back to Top
 
ApeNut
Newbie


Joined: 05 June 2011
Location: United States
Posts: 3
Posted: 14 June 2011 at 1:46am

Thank you very much Anton.  Yes.  I have both !-f and !-d there.  I was just trying things to get it to work since if a visitor came with site.com/State/City/ my base URL would be /state and not the root. All css and images were broken.

But I figured it out after looking to your past posts.  I changed all my links from relative to absolute (all images to /images) and now it works perfectly.

I'm also using SEORule and one issue that I have now is that the links are not changed if we have something like this id=55&state=ca.  The regex has it has id=(\d+)\&state=(.+). 

Thanks again!

 

 

 

Back to Top
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 16 June 2011 at 6:31am

Please try to change your regex for SeoRule as follows:

id=(\d+)(?:&|&)state=(.+)

__________________
Regards,
Anton
Back to Top
 

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

Printable version Printable version