Page 1 of 1
How do you use HTACCESS to set and 301 UPPER to lower case?
Posted: Thu Feb 18, 2016 5:42 am
by simonmlewis
Code: Select all
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
We need to do 301s so that any URL in uppercase, 301s to lowercase. This is the script we have found that could do it, but not sure about the conf file with the "lc".
Is there no other simple htaccess way?
Re: How do you use HTACCESS to set and 301 UPPER to lower ca
Posted: Thu Feb 18, 2016 7:28 am
by Celauran
RewriteMap needs to go in your virtual host definition, not your .htaccess
While you cannot declare a map in per-directory context (.htaccess files or <Directory> blocks) it is possible to use this map in per-directory context.
https://httpd.apache.org/docs/current/r ... temap.html
Re: How do you use HTACCESS to set and 301 UPPER to lower ca
Posted: Thu Feb 18, 2016 7:30 am
by Celauran
However, this would be trivial to implement in PHP.
Re: How do you use HTACCESS to set and 301 UPPER to lower ca
Posted: Thu Feb 18, 2016 7:40 am
by simonmlewis
Is it important to do this - because we have pages that are apparently cached by Google with CAPITALS, and the same with lowercase.
So should we be finding a way to 301 to lowercase?
Re: How do you use HTACCESS to set and 301 UPPER to lower ca
Posted: Thu Feb 18, 2016 7:53 am
by simonmlewis
Code: Select all
<font color='#ffffff'>
<?php
$uppercaseurlcheck = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$pos = strcspn($uppercaseurlcheck, 'ABCDEFGHJIJKLMNOPQRSTUVWXYZ');
if ($pos < strlen($string)) {
echo "capital letter as index $pos";
}
else { echo "nothing caps";}
?></font>
Hi
I'm am sort of getting there. Using this as an include file just to test it. But it's erroring on line six,
Re: How do you use HTACCESS to set and 301 UPPER to lower ca
Posted: Thu Feb 18, 2016 9:36 am
by Celauran
Seems unnecessarily complex.
Convert the request to lower case. Compare against the original request. If original is different (ie. not lower case), redirect.
Code: Select all
<?php
$request_uri = $_SERVER['REQUEST_URI'];
if (strtolower($request_uri) !== $request_uri) {
// redirect
}
Re: How do you use HTACCESS to set and 301 UPPER to lower ca
Posted: Thu Feb 18, 2016 10:41 am
by simonmlewis
Code: Select all
$uppercaseurlcheck = $_SERVER['REQUEST_URI'];
$converttolower = strtolower($uppercaseurlcheck);
if(preg_match('/[A-Z]/', $uppercaseurlcheck)){
header("Location: http://site.co.uk" . $converttolower,TRUE,301);
exit();
}
This is what I opted for before I saw your message. Similar?
Re: How do you use HTACCESS to set and 301 UPPER to lower ca
Posted: Thu Feb 18, 2016 10:52 am
by Celauran
Pretty much the same thing, yeah