redirect if url contains uppercase

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 17 Jul 2013, 09:40

redirect if url contains uppercase

17 Jul 2013, 09:42

Hi all

im trying to create a rule that checks the url and if it contains upper case characters redirect them to the same url but all in lowercase.

can anyone help

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

Re: redirect if url contains uppercase

17 Jul 2013, 20:54

Hello,

You'd need to use CL-flag.

CL (Case Lower)
Changes the case of substitution result to lower


So the rule would look like:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteRule (.*[A-Z].*) /$1 [CL,R=301,L]


Regards
Andrew

User avatar
Posts: 4
Joined: 17 Jul 2013, 09:40

Re: redirect if url contains uppercase

18 Jul 2013, 09:04

Hi thanks for that

im using the following code

RewriteEngine on
RewriteBase /

RewriteRule (.*[A-Z].*) /$1 [CL,R=301,L]
RewriteRule ^/sitemap$ /index.php?params=sitemap [NC,L,I]

so if I browse to www.mysite.com/SITEMAP it redirects to www.mysite.com/sitemap but then can't find the page index.php

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

Re: redirect if url contains uppercase

18 Jul 2013, 10:31

Strange, shouldn't be this way.
Ty to enable logging and provide us with rewrite.log for a testing request. Logging issues are described here - http://www.helicontech.com/forum/10648-FAQ.html

Regards
Andrew

User avatar
Posts: 4
Joined: 17 Jul 2013, 09:40

Re: redirect if url contains uppercase

19 Jul 2013, 05:32

hi log output as requested, thanks for the help by the way

(1) Htaccess process request D:\inetpub\wwwroot\test\httpd.conf
(3) applying pattern '(.*[A-Z].*)' to uri 'SITEMAP'
(1) escaping /sitemap
(2) explicitly forcing redirect with http://192.168.50.2/sitemap
(2) internal redirect with /SITEMAP [INTERNAL REDIRECT]

(2) init rewrite engine with requested uri /sitemap
(1) Htaccess process request D:\inetpub\wwwroot\test\httpd.conf
(3) applying pattern '(.*[A-Z].*)' to uri 'sitemap'
(3) applying pattern '^/sitemap$' to uri 'sitemap'
(2) init rewrite engine with requested uri /favicon.ico
(1) Htaccess process request D:\inetpub\wwwroot\test\httpd.conf
(3) applying pattern '(.*[A-Z].*)' to uri 'favicon.ico'
(3) applying pattern '^/sitemap$' to uri 'favicon.ico'

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

Re: redirect if url contains uppercase

19 Jul 2013, 12:39

Here's the answer:

(3) applying pattern '^/sitemap$' to uri 'sitemap'


You see the '/' in the pattern? Just remove it from the rule.

Regards
Andrew

User avatar
Posts: 4
Joined: 17 Jul 2013, 09:40

Re: redirect if url contains uppercase

22 Jul 2013, 05:17

Brilliant thanks very much

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 16 guests