Topic: Combine Trailing Slash and Lowercase URLs
|

|
| Author |
|
billr578 Newbie

Joined: 17 August 2006 Location: United States
Online Status: Offline Posts: 28
|
| Posted: 01 February 2012 at 3:18pm | IP Logged
|
|
|
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 |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -149
|
| Posted: 03 February 2012 at 7:26am | IP Logged
|
|
|
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
Online Status: Offline Posts: 28
|
| Posted: 03 February 2012 at 9:20am | IP Logged
|
|
|
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 |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -149
|
| Posted: 06 February 2012 at 5:53am | IP Logged
|
|
|
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
Online Status: Offline Posts: 28
|
| Posted: 06 February 2012 at 9:17am | IP Logged
|
|
|
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 |
|
| |
|
|
If you wish to post a reply to this topic you must first login
If you are not already registered you must first register
|
|
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
|