| Author |
|
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 13 May 2008 at 6:09am | IP Logged
|
|
|
Hi All,
First of all, it's my first time here and I'm a complete ISAPI / URL rewriting newbie so apologies in advance if this may have already been answered somewhere (and I'm trying to get up to speed with all of the documentation) but I wondered if someone might be able to help me with the following?
I need to set up ISAPI rewrite on my site and primarily want to be able to create URL's such as:
www.mysite.com/usa (which would actually be www.mysite.com/folder/file.asp?variable=1)
www.mysite.com/florida (which would actually be www.mysite.com/folder/file.asp?variable=1&variable=2 )
www.mysite.com/orlando (which would actually be www.mysite.com/folder/file.asp?variable=1&variable=2&variable=3 )
and finally....
www.mysite.com/davenport (which would actually be www.mysite.com/folder/file.asp?variable=1&variable=2&variable=3&variable=4 )
I've seen from the documentation how I could do this if I included the variable in the URL (i.e. davenport-1-2-3-4), but ideally I'd like to just have the words in the URL. Is this possible?
Also, I need to accommodate paging I guess? So something like:
www.mysite.com/folder/file.asp?variable=1&variable=2&variable=3&variable=4&page=1
would become:
www.mysite.com/davenport/p1
Feel a bit out of my league on this at the mo so any help / tips would be really welcome! 
Thanks Kessa
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 13 May 2008 at 6:18am | IP Logged
|
|
|
Whoops - sorry, forgot to mention that some of the resulting new URL's will probably have spaces in them (i.e. "Costa Blanca") so need to also replace any spaces with hypens (i.e. "costa-blanca").
Also, (just thinking agead) I don't think any of the locations already include hyphens, but is there a way to only include a hypen if one doesn't exist? I'm just trying to avoid getting something like "costa--blanca"
Thanks
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7468
|
| Posted: 16 May 2008 at 4:33pm | IP Logged
|
|
|
With ISAPI_Rewrite 2 you will need to write a separate rule for each URL. So, I would recommend you to look at ISAPI_Rewrite 3 and its "map files" feature.
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 17 May 2008 at 7:03pm | IP Logged
|
|
|
bugger -pls tell me u r kidding 
I've got thousands of urls to rewrite and apparently the host only has v2 installed - they tried v3 but apparently had loads of problems with it
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7468
|
| Posted: 19 May 2008 at 7:05am | IP Logged
|
|
|
I am not kidding. There is no any generic relation between real and "user-friendly" URLs in your sample. So, there is no way to create a generic rule (or ruleset) for such transformation. The only good way to do that with ISAPI_Rewrite 2 is to rewrite all requests to a script that will perform a required mapping.
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 20 May 2008 at 12:08pm | IP Logged
|
|
|
OK, thanks Lexey - much appreciated. I've contacted the host to see if they can move to version 3. Fingers crossed.
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 20 May 2008 at 12:10pm | IP Logged
|
|
|
Actually, in the mean time, would you be able to give me some pointers about how I could do the individual rules in version2 - at least from the front end point of view I would be able to start introducing these for the search engines to begin crawling.
Thanks
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 23 May 2008 at 5:23am | IP Logged
|
|
|
Hi Guys,
Just following up on this - I found this in the documentation:
"Another and more complex solution is to create 1 to 1 map file and use it to map “our_super_tool” to 127. This solution is useful for some long URLs with many parameters and will allow you to hide even numeric identifier. The URL will look as http://www.mysite.com/products/our_super_tool.asp. Please note that “our_super_tool” part should uniquely identify the product and it’s identifier. Here is an example for this solution:
RewriteEngine on RewriteBase / RewriteMap mapfile txt:mapfile.txt RewriteRule ^products/([^?/]+)\.asp /productpage.asp?productID=${mapfile:$1} |
And you will need to create mapfile.txt map file with the following content:
one_product 1 another_product 2 our_super_tool 127 more_products 335 | "
.....which is a great start, but I'm not sure how I would go about converting URL's with more than 1 variable?
Any advice / help would be much appreciated.
Thanks Kessa
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7468
|
| Posted: 23 May 2008 at 9:05am | IP Logged
|
|
|
RewriteRule /usa /folder/file.asp\?variable=1 [I,L]
RewriteRule /florida /folder/file.asp\?variable=1&variable=2 [I,L]
etc
|
| Back to Top |
|
| |
xoise Newbie

Joined: 23 May 2008
Online Status: Offline Posts: 9
|
| Posted: 23 May 2008 at 5:19pm | IP Logged
|
|
|
Also, if you're pulling the variables from a database (and that's where you get the country/city/state from), surely they have some sort of ID associated with them. In that case, the following rule would be just fine, but your URL would look slightly different...still just fine though:
RewriteRule /([a-z]*)-([0-9]*)$ /folder/file.asp?variable=$2 [I,NC,L]
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 28 May 2008 at 4:20am | IP Logged
|
|
|
Brilliant - thanks both.
Xoise - when you say the URL would look slightly different, could you show an example please? Also, using your method how would I go about handling the various variable levels? For example, would I need to do the following?
RewriteRule /([a-z]*)-([0-9]*)$ /folder/file.asp?variable=$1[I,NC,L] RewriteRule /([a-z]*)-([0-9]*)$ /folder/file.asp?variable=$2 [I,NC,L] RewriteRule /([a-z]*)-([0-9]*)$ /folder/file.asp?variable=$3 [I,NC,L]
Sorry, I'm new to all this so still trying to get my head around it.
Thanks
|
| Back to Top |
|
| |
xoise Newbie

Joined: 23 May 2008
Online Status: Offline Posts: 9
|
| Posted: 28 May 2008 at 10:09am | IP Logged
|
|
|
An example for the rewriterule I gave you would be a URL like.
/florida-234
florida would just be in the URL for SEO purposes - 234 would be the ID to use in the database.
You wouldn't do what you said...all of the RewriteRules you posted are the same...it wouldn't get past the first rule.
Using $X (X = any number) grabs what was in the pretty URL in the X matched group...which is something between parenthesis.
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 04 June 2008 at 7:30am | IP Logged
|
|
|
Hi Guys,
OK, I've decided to go with the 1-2-1 delaration for the time being as the host has said they won't move to version 3 yet.
With that in mind, here's an example of my code so far:
[ISAPI_Rewrite] # do not delete the line above
RewriteEngine on # Commented
# Block access to the httpd.ini RewriteRule /httpd(?:\.ini|\.parse\.errors) / [F,I,O]
# Block access to Helper ISAPI RewriteRule .*\.isrwhlp / [F,I,O]
#Fix missing trailing slash char on folders RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]
#Rules RewriteRule ^/spain/$ /folder/file.asp?variable=5
My next question is, how do I get it to check to make sure the user hasn't tried to add an extention such as .asp / .html, etc?
I did try using this bit of code from the documentation but it didn't work so I suspect I may be implementing it wrongly:
#Redirect extension requests to avoid duplicate content RewriteRule ^([^?]+)\.asp$ $1 [NC,R=301,L]
#Internally add extensions to request RewriteCond %{REQUEST_FILENAME}.asp -f RewriteRule (.*) $1.asp
(I added this above the "fix missing training slash" command thinking it would strip off the extention... then the fix trailing slash adds the slash, and then the last rule does the final redirect)
Thanks
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7468
|
| Posted: 04 June 2008 at 3:06pm | IP Logged
|
|
|
Quote:
My next question is, how do I get it to check to make sure the user hasn't tried to add an extention such as .asp / .html, etc?
I did try using this bit of code from the documentation but it didn't work so I suspect I may be implementing it wrongly:
#Redirect extension requests to avoid duplicate content
RewriteRule ^([^?]+)\.asp$ $1 [NC,R=301,L]
|
|
|
Do you want to remove exists .asp and .html extensions?
If so, the following rule will work:
RewriteCond Host: (.*)
RewriteRule ([^?]*)\.(?:asp|html)(?:\?.*)? http\://$1$2 [I,RP]
Quote:
#Internally add extensions to request
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule (.*) $1.asp |
|
|
ISAPI_Rewrite 2 does not support file existance checks.
|
| Back to Top |
|
| |
kessa Newbie

Joined: 13 May 2008 Location: United Kingdom
Online Status: Offline Posts: 9
|
| Posted: 04 June 2008 at 6:04pm | IP Logged
|
|
|
Hi Lexy,
Thanks. I've added that but it redirects to:
/folder/file/ rather than /spain/
Am I missing something?
Thanks
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7468
|
| Posted: 09 June 2008 at 3:59pm | IP Logged
|
|
|
Heh, that is not simple extension removal. That is a complete reverse mapping. And it will require the same number of "backward" rules as a number of "forward" ones. Rules could be like:
RewriteCond Host: (.*)
RewriteRule /folder/file\.asp\?variable=5 http\://$1/spain/ [I,RP]
|
| Back to Top |
|
| |