This forum has been moved here:
Helicon Tech Community Forum

  Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
Helicon Ape
 Helicon Tech : Helicon Ape
Subject Topic: URI to Querystring Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
ApeNut
Newbie
Newbie


Joined: 05 June 2011
Location: United States
Online Status: Offline
Posts: 3
Posted: 09 June 2011 at 8:33pm | IP Logged Quote ApeNut

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 View ApeNut's Profile Search for other posts by ApeNut
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10520
Posted: 10 June 2011 at 5:07am | IP Logged Quote Anton

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 View Anton's Profile Search for other posts by Anton
 
ApeNut
Newbie
Newbie


Joined: 05 June 2011
Location: United States
Online Status: Offline
Posts: 3
Posted: 10 June 2011 at 12:39pm | IP Logged Quote ApeNut

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 View ApeNut's Profile Search for other posts by ApeNut
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10520
Posted: 14 June 2011 at 1:38am | IP Logged Quote Anton

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 View Anton's Profile Search for other posts by Anton
 
ApeNut
Newbie
Newbie


Joined: 05 June 2011
Location: United States
Online Status: Offline
Posts: 3
Posted: 14 June 2011 at 1:46am | IP Logged Quote ApeNut

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&amp;state=ca.  The regex has it has id=(\d+)\&state=(.+). 

Thanks again!

 

 

 

Back to Top View ApeNut's Profile Search for other posts by ApeNut
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10520
Posted: 16 June 2011 at 6:31am | IP Logged Quote Anton

Please try to change your regex for SeoRule as follows:

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

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You can vote in polls in this forum