redirect help... Ending Default.aspx

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 8
Joined: 18 Dec 2012, 11:49

redirect help... Ending Default.aspx

03 Jun 2013, 17:14

Here is what i'm trying to do...

'I want to still be able to use real aspx pages at the root
http://www.sample.com/real.aspx

'Rewrite Category Pages
http://www.sample.com/example-category/default.aspx
http://www.sample.com/example-category/ -> redirect back to http://www.sample.com/example-category/default.aspx
http://www.sample.com/example-category -> redirect back to http://www.sample.com/example-category/default.aspx

'Rewrite Sub Categories
http://www.sample.com/example-category/example-sub-cat.aspx
http://www.sample.com/example-category/sub-cat-title-again.aspx

Can anybody help shine some light on this? I just keep getting failed attempts

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: redirect help... Ending Default.aspx

04 Jun 2013, 05:50

Hello,

Please try to use the following rules:

RewriteBase /
RewriteRule ^([^./]+)/?$ /$1/default.aspx [R=301,L]

and as for sub-categories, I didn't understand what to rewrite/redirect and where. Please clarify.

User avatar
Posts: 8
Joined: 18 Dec 2012, 11:49

Re: redirect help... Ending Default.aspx

04 Jun 2013, 10:29

Thanks for the reply...

as for the sub-categories it will be as followed.

'Rewrite Sub Categories
http://www.sample.com/example-category/example-sub-cat.aspx -> subpage_lookup.aspx?title=?
http://www.sample.com/example-category/another-fake-directory/sub-cat-title-again.aspx -> subpage_lookup.aspx?title=?

but there can be unlimited sub directories so would I have to use more than one rule to handle each of the directories?

User avatar
Posts: 8
Joined: 18 Dec 2012, 11:49

Re: redirect help... Ending Default.aspx

04 Jun 2013, 10:54

Ok, so here is what I've came up with

RewriteBase /
RewriteRule ^([^./]+)/?$ /$1/default.aspx [R=301,L]
RewriteRule ^([^./]+)/([^./]+)/?$ /$1/default.aspx [R=301,L]
RewriteRule ^([^./]+)/default\.aspx$ /page.aspx?title=$1 [NC,L]
RewriteRule ^([^./]+)/([^./]+)/default\.aspx$ /page.aspx?title=$1 [NC,L]

RewriteRule ^([^./]+)/([^./]+)\.aspx$ /page.aspx?title=$1 [NC,L]
RewriteRule ^([^./]+)/([^./]+)/([^./]+)\.aspx$ /page.aspx?title=$1 [NC,L]

but it will only handle up to 2 sub-directories
basically I will be doing a lookup on the url to get the page content. and the urls will be based on the site hierarchy
is there a way to reduce this or make it better?

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

Re: redirect help... Ending Default.aspx

06 Jun 2013, 10:00

Hello,

Our extensive experience tells that it's better to have a little more simple rules than one cumbersome rule. Reason for that is that a complicated big rule may sometimes fail to match the intended URL.

We strongly recommend creating a separate rule for a case, though we could have done it in less number of lines.
(having extra 20, 30, 50 lines or rules has never made any difference in terms of performance)

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 17 guests