.htaccess lowercase rewrite is not working
.htaccess lowercase rewrite is not working
Very new to Apache here and htaccess rules. Please assume I'm doing something fundamentally wrong here. This is currently trying to be achieved currently on MAMP pro.
I'm trying to force all URL's to redirect to a lowercase version if the URL has any uppercase letters in it.
The solutions I'm finding are not reaping any results. .htaccess
markup is as follows:
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# PROBLEM HERE: apparently this works
CheckSpelling on
CheckCaseOnly on
# END PROBLEM
# 301 redirect with trailing slash
RewriteCond %{REQUEST_URI} /+[^.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And when it comes to adding this to the httpd.conf
:
httpd.conf
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
the server then does nothing. I've attempted wrapping it in <Directory>
and <Virtualhost>
but to no avail.
<Directory>
<Virtualhost>
Updated to include error
– DevLime
Jul 2 at 12:01
httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap says it should be within the server config or the virtualhost config. Also, my gut feeling says that the internal router of Wordpress may be causing you issues too
– Sumurai8
Jul 2 at 12:02
When I add it to the MAMP httpd conf, it doesn't change anything when not wrapped, or wrapped in
<Virtualhost>
or <Directory>
– DevLime
Jul 2 at 12:05
<Virtualhost>
<Directory>
Wordpress has an internal router. It matches the url according to some url structure you have set up. Even if this RewriteMap did work as expected, you may end up with an url that Wordpress does not recognise, or an url that Wordpress will rewrite to a known url based on some algorithm. My best guess is that you did not restart Apache after changing your config, but I would recommend to change your
301
to 302
redirects to avoid sticky redirects when testing your code. Can you elaborate on what you want to achieve with this redirect?– Sumurai8
Jul 2 at 17:45
301
302
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Well in the case where “it errors”, you go “check log” first of all …
– CBroe
Jul 2 at 11:57