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: Combine Trailing Slash and Lowercase URLs
Author
Message |
billr578
Newbie


Joined: 17 August 2006
Location: United States
Posts: 28
Posted: 01 February 2012 at 3:18pm

Hi,

I have two rewrite conditions to handle for a missing
slash on all URLs as well as making sure all of our URLs
are redirected to the lowercase version:

# Fix missing slash on folders
RewriteCond %{HTTP:Host} (.*)
RewriteRule ^([^.?]+[^.?/])(\?.*)?$ http\://%1$1/$2
[NC,R=301]

# We want all lowercase URLs
RewriteCond %{REQUEST_URI} !\.
(?:axd|asmx|aspx|jpg|gif|png|css|js)
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule .? %{REQUEST_URI} [CL,R=301,L]

One problem we're noticing is that with two separate
URLs, you could end up with multiple 301 redirects, i.e.
no trailing slash AND upper case characters in the URL.

My question is, is there an easy way to combine all of
this into one rewrite condition to handle all cases while
only doing one 301 redirect?

Any assistance (or even a solution) is GREATLY
appreciated. Thanks in advance!

Regards,
Bill Rowell
http://www.billrowell.com/
Back to Top Visit billr578's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 03 February 2012 at 7:26am

Hello Bill,

Try using the following rule:

# Fix missing slash on folders
RewriteCond %{HTTP:Host} (.*)
RewriteRule ^([^.?]+[^.?/])(\?.*)?$ http\://%1$1/$2 [NC,CL,R=301]


Regards
Andrew

Back to Top
 
billr578
Newbie


Joined: 17 August 2006
Location: United States
Posts: 28
Posted: 03 February 2012 at 9:20am

Hi Andrew,

Unfortunately that didn't work. It fixed the trailing
slash, but would not redirect to an all lowercase URL. I
think a combination of both of the rewrites I'm using now
is necessary, I just can't get it to work properly.

Regards,
Bill Rowell
http://www.billrowell.com/
Back to Top Visit billr578's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 06 February 2012 at 5:53am

Lets take a look at how the request is processed.
Please, provide the rewrite.log for the testing request.
Logging issues described in FAQ

Regards
Andrew
Back to Top
 
billr578
Newbie


Joined: 17 August 2006
Location: United States
Posts: 28
Posted: 06 February 2012 at 9:17am

I ended up using something like this based on your
suggestion and another thread:

# Fix missing slash on folders make all URLs lowercase
RewriteCond %{REQUEST_URI} !\.
(?:axd|asmx|aspx|jpg|gif|png|css|js) [NC]
RewriteRule ^([^.?]+[^.?/])$ $1/ [CL,R=301,L]

RewriteCond %{REQUEST_URI} !\.
(?:axd|asmx|aspx|jpg|gif|png|css|js)
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule .? %{REQUEST_URI} [CL,R=301,L]

So the top part works for all the cases EXCEPT when the
trailing slash is already there and there are uppercase
characters. So it will fall through to the second case.

Its probably not ideal, but its at least working.

-Bill
Back to Top Visit billr578's Homepage
 

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

Printable version Printable version