0

What am I trying to achieve?

I want to convert all URL's that are within the /migrate directory (and subdirectories) to lowercase.

What have I done?

I have migrated my website from DNN to Wordpress. Therefore I have URL's in my posts that reference images with a combination of upper and lowercase letters.

All of my directories and files on disk in the /migrate folder (and subfolders) are lowercase.

When I view an article, if the reference to the image has an uppercase character, I am getting a 404 which is expected.

For example:

https://xxx.domain.net/wp-content/migrate/ABC/image.jpg

https://xxx.domain.net/wp-content/migrate/Xyz/image.jpg

https://xxx.domain.net/wp-content/migrate/abc/Image.jpg

https://xxx.domain.net/wp-content/migrate/ABC/Xyz/image.jpg

So after reading various articles online and on here I tried a few things:

1) Enabled mod_speling and added this to apache2.conf

LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so
<IfModule mod_speling.c>
CheckSpelling On
CheckCaseOnly On
</IfModule>

This didn't work, continued to get 404's.

2) Tired to use Rewritemap in my /etc/sites-enabled/mysite.conf file.

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} /migrate [A-Z]
RewriteRule  ^(.*)$ /${lc:$1} [R=301,L]

However this would rewrite all URL's to lowercase and it broke some of the Wordpress plugins and editors as the files on disk had uppercase characters.

My .htaccess file in the Wordpress root directory is as follows:

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

#BEGIN Wordpress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
halfer
  • 19,824
  • 17
  • 99
  • 186
Nanz
  • 179
  • 2
  • 14

1 Answers1

0

After hours and hours of trying different things and reading through the logs, I have worked this out!

Basically I needed to ignore all the other Wordpress directories from rewriting.

RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
RewriteCond %{REQUEST_URI} !^/wp-content/themes/
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/
RewriteCond %{REQUEST_URI} !^/wp-includes/
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteRule ^/?(.*)$ /${lc:$1} [R=301,L]
Nanz
  • 179
  • 2
  • 14