This forum has been moved here:
Helicon Tech Community Forum

ISAPI_Rewrite 3.0 (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 3.0
Subject Topic: Rewrite rule help
Author
Message |
Pascal
Newbie


Joined: 19 July 2011
Posts: 8
Posted: 19 July 2011 at 12:21am

Please excuse me, I'm a major novice when it comes to this!

I have a rewrite rule that is working OK, except for one thing. The code is below:

Code:

RewriteBase /
RewriteMap mapfile txt:mapfile/mapfile.txt
RewriteCond %{QUERY_STRING} ^pageid=[^&]+&n=(.+)
RewriteRule ^sitepages/content\.asp$ content/%1? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^content/([^/]+)$ sitepages/content.asp?pageid=${mapfile:$1}&n=$1 [NC,L]


So my ASP page may be www.domain.com/sitepages/content.asp?pageid=2 and the rewrite means the page works as www.domain.com/content/thepage

My problem is if someone puts a / on the end of the URL (ie www.domain.com/content/thepage/) then the page doesn't work.

Can anyone assist with the above rule so that both cases work? (ie with the / and without should work the same).

Hope that makes sense. Thanks in advance.
Back to Top
 
Pascal
Newbie


Joined: 19 July 2011
Posts: 8
Posted: 20 July 2011 at 3:39am

Anyone? 
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 20 July 2011 at 4:24am

Hello,


Please, try replacing the following
Code:
RewriteRule ^content/([^/]+)$ sitepages/content.asp?pageid=${mapfile:$1}&n=$1 [NC,L]

with
Code:
RewriteRule ^content/([^/]+)/?$ sitepages/content.asp?pageid=${mapfile:$1}&n=$1 [NC,L]



Regards
Andrew
Back to Top
 
Pascal
Newbie


Joined: 19 July 2011
Posts: 8
Posted: 20 July 2011 at 5:37am

Thanks so much Andrew.
Back to Top
 
Pascal
Newbie


Joined: 19 July 2011
Posts: 8
Posted: 11 August 2011 at 7:54pm

Just a follow up and apoligies for my newbie-ness!

The above worked perfectly - thank you.

I am now wondering how I can achieve this. The pages listed above have sub-pages. The full URL for these subpages would be www.domain.com/sitepages/contentSub.asp?subpageid=2

So I would like this type of heirarchy:

www.domain.com/content/thepage/

and then the sub page

www.domain.com/content/thepage/thesubpage/

Can I have another column in my mapfile.txt file that may look something like this:

Code:

thepage1 thesubpage1 1
thepage1 thesubpage2 2
thepage1 thesubpage3 3
thepage1 thesubpage4 4
thepage2 thesubpage5 5
thepage2 thesubpage6 6


Does that make sense? Any help greatly appreciated. Thank you.
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 12 August 2011 at 4:30am

No, mapfiles is designed in a very specific way, that you can have only 2 columns.
You'l have do create a new mapfile with subpages only and match it separately.

Regards
Andrew
Back to Top
 
Pascal
Newbie


Joined: 19 July 2011
Posts: 8
Posted: 15 August 2011 at 11:57pm

Just following up again! Sorry for my newbness.

I did come up with a solution that converts something like:
http://www.mysite.com/sitepage/content.asp?smid=1

into something like this:

http://www.mysite.com/folder/subfolder

by way of this:

Code:

RewriteBase /
RewriteMap mapfile txt:mapfile/mapfile.txt [NC]
RewriteMap mapfileFolder txt:mapfile/mapfileFolder.txt [NC]
RewriteCond %{QUERY_STRING} ^smid=[^&]+&n=(.+) [NC]
RewriteRule ^sitepage/content\.asp$ ${mapfileFolder:%1}/%1? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]+/([^/]+)/?$ sitepage/content.asp?smid=${mapfile:$1}&n=$1 [NC,L]


The /folder comes from mapfilefolder.txt

Now I am just wondering how I could go a third level? Can I add another mapfile here which would be the subfolder? I want the URL to go from:

http://www.mysite.com/sitepage/contentsub.asp?ssmid=1

into:

http://www.mysite.com/folder/subfolder/subsubfolder

I have tried the below but I have obviously stuffed up somewhere. Hope this makes sense.

Code:

RewriteBase /
RewriteMap mapfilesub txt:mapfile/mapfilesub.txt [NC]
RewriteMap mapfilesubfolder2 txt:mapfile/mapfilesubfolder2.txt [NC]
RewriteMap mapfilesubfolder1 txt:mapfile/mapfilesubfolder1.txt [NC]
RewriteCond %{QUERY_STRING} ^ssmid=[^&]+&n=(.+) [NC]
RewriteRule ^sitepage/contentsub\.asp$ ${mapfilesubfolder1:%1}/{mapfilesubfolder2:%1}/%1? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]+/([^/]+)/([^/]+)/?$ sitepage/contentsub.asp?ssmid=${mapfilesub:$1}&n=$1 [NC,L]

Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 17 August 2011 at 5:29am

Seems like you've lost '$' in the following:
Code:
RewriteRule ^sitepage/contentsub\.asp$ ${mapfilesubfolder1:%1}/{mapfilesubfolder2:%1}/%1? [NC,R=301,L]

try to use:
Code:
RewriteRule ^sitepage/contentsub\.asp$ ${mapfilesubfolder1:%1}/%{mapfilesubfolder2:%1}/%1? [NC,R=301,L]


and make sure you mapfilesub has content opposite to mapfilesubfolder2, not mapfilesubfolder1

Regards
Andrew
Back to Top
 
Pascal
Newbie


Joined: 19 July 2011
Posts: 8
Posted: 08 March 2012 at 6:01pm

Just thought I'd dredge up an old thread. A couple of questions.

1. I have a rewrite rule that works partially.

Code:
RewriteRule events sitepages/events.asp


So when someone types in www.mysite.com/events/ this seems to work fine, but if someone doesn't put the '/' on the end of the URL it doesn't work. So I then tried

Code:
RewriteRule events sitepages/events.asp
RewriteRule events/ sitepages/events.asp


but it still doesn't seem to make a difference. Is there a way to make it so the rewrite will work whether or not you put the / on the end of the URL?

2. I also have another similar situation with a more complex rewrite.

Code:
RewriteBase /
RewriteMap mapfile txt:mapfile/mapfile.txt
RewriteCond %{QUERY_STRING} ^pageID=[^&]+&n=(.+)
RewriteRule ^sitepages/content\.asp$ %1? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ sitepages/content.asp?pageID=${mapfile:$1}&n=$1 [NC,L]


Now this will turn www.mysite.com/sitepages.asp?pageID=2 into something like www.mysite.com/my-page.

Now again, I want to make it so that the rule will work whether the user puts the '/' on the end of the URL or not.

Thanks in advance.
Back to Top
 
HeliconA
Admin Group


Joined: 02 March 2012
Posts: 4142
Posted: 12 March 2012 at 4:36am

Hello,

Regarding the first rule, you need to provide rewrite.log so that we'd analyze the issue.

Your second tule might be fixed by the following:

Code:
RewriteBase /
RewriteMap mapfile txt:mapfile/mapfile.txt
RewriteCond %{QUERY_STRING} ^pageID=[^&]+&n=(.+)
RewriteRule ^sitepages/content\.asp$ %1? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ sitepages/content.asp?pageID=${mapfile:$1}&n=$1 [NC,L]


Regards
Andrew
Back to Top
 
Pascal
Newbie


Joined: 19 July 2011
Posts: 8
Posted: 12 March 2012 at 6:24pm

That's great...thanks so much!

I'll try and find the logs and post back.
Back to Top
 

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

Printable version Printable version