Profile Photo

Servers and Networks

  • 3 months ago
  • 15

    Posts

  • 6

    Members

Apache HTTPD mod_rewrite RewriteMap lc int:tolower UPPERCASE to lowercase URLs

SEO Marketing and Advertising Chat Forums and Technical Discussion Forums Servers and Networks Apache HTTPD mod_rewrite RewriteMap lc int:tolower UPPERCASE to lowercase URLs

last updated by admin 3 months ago
2 voices
3 replies
  • Author
    Posts
  • #129
    James Roberts
    Participant

    Hello, thank you for helping out. I’m having an issue after switching to apache on Centos 7.

    In the past I have always used, for many years now, in httpd conf
    RewriteMap lc int:tolower and in htaccess

    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]

    This 301 redirect for all UPPERCASE characters in a URL to the same but in lowercase.

    Except now, on my Centos7 machine this seems to be causing some issue.

    It seems instead of redirecting with a 301 to lower case the above now redirects to domain root on main domain, https://www.example.com, and for m. (dedicated mobile) redirects to the document root’s full server path, i.e https://m.example.com/var/www/html/documentroot

    This worked fine on my old server, I dont see any errors in log files.

    I tried many examples from google results, similar to the above but none work as expected. I did however come across this which works

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule [A-Z] - [E=HASCAPS:TRUE,S=1]
    RewriteRule ![A-Z] - 
    RewriteRule ^([^A]*)A(.*)$ $1a$2
    RewriteRule ^([^B]*)B(.*)$ $1b$2
    RewriteRule ^([^C]*)C(.*)$ $1c$2
    RewriteRule ^([^D]*)D(.*)$ $1d$2
    RewriteRule ^([^E]*)E(.*)$ $1e$2
    RewriteRule ^([^F]*)F(.*)$ $1f$2
    RewriteRule ^([^G]*)G(.*)$ $1g$2
    RewriteRule ^([^H]*)H(.*)$ $1h$2
    RewriteRule ^([^I]*)I(.*)$ $1i$2
    RewriteRule ^([^J]*)J(.*)$ $1j$2
    RewriteRule ^([^K]*)K(.*)$ $1k$2
    RewriteRule ^([^L]*)L(.*)$ $1l$2
    RewriteRule ^([^M]*)M(.*)$ $1m$2
    RewriteRule ^([^N]*)N(.*)$ $1n$2
    RewriteRule ^([^O]*)O(.*)$ $1o$2
    RewriteRule ^([^P]*)P(.*)$ $1p$2
    RewriteRule ^([^Q]*)Q(.*)$ $1q$2
    RewriteRule ^([^R]*)R(.*)$ $1r$2
    RewriteRule ^([^S]*)S(.*)$ $1s$2
    RewriteRule ^([^T]*)T(.*)$ $1t$2
    RewriteRule ^([^U]*)U(.*)$ $1u$2
    RewriteRule ^([^V]*)V(.*)$ $1v$2
    RewriteRule ^([^W]*)W(.*)$ $1w$2
    RewriteRule ^([^X]*)X(.*)$ $1x$2
    RewriteRule ^([^Y]*)Y(.*)$ $1y$2
    RewriteRule ^([^Z]*)Z(.*)$ $1z$2
    RewriteRule [A-Z] - [N]
    RewriteCond %{ENV:HASCAPS} TRUE
    RewriteRule ^/?(.*) /$1 [R=301,L]
    </IfModule>

    however, I just want my simple code back – this example just seems silly and potentially resource hungry?

    So if you could help, why would these lowercase redirects, on switching to HTTPD on Centos7 now redirect to domain root and document root urls?

    0
    #130
    James Roberts
    Participant

    Welp in the end, after setting up mod_rewrite logging to see what was going on, with
    LogLevel alert rewrite:trace5
    it wasnt doing anything. Turned out the config what was working in virtualhosts on my old machine, now needed to be placed in the SSL conf.

    So. If you want to redirect all your uppercase urls to lowercase, with apache and .htaccess this still works fine

    RewriteMap lc int:tolower
    in your config
    and

    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]

    in your .htaccess file.

    0
    #549
    admin
    Keymaster

    I just had to do the same, but your htaccess did not work. This did

    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule (.*) ${lc:$1} [R=301,L]
    0
    #553
    admin
    Keymaster

    I’ve now switched to this, to check if the file exists, as I have one real CSS file that is camelCase

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]
    0

You must be logged in to reply to this topic.

Description

Servers, Hosting, CDNs, Operating Systems, Hardware, Services, Networks and more…

Group Administrators

Hashtags

#questions
2 Hashtags
#hashtags
1 Hashtag
#VideoMarketing
1 Hashtag
#VideoContent
1 Hashtag