Jump to content

Recommended Posts

Posted

This is something I've just noticed when settingup some redirect. Let me use an example on the processwire.com site:

https://processwire.com/docs/
https://processwire.com/dOcs/

This both load the same page. Processwire does make the canonical tag lowercase.

I just wondered though, is there a system-wide way of directing all requests that aren't files to be lowercase:

www.site.com/files/I_am_a_PDF.pdf -> fine
www.site.com/folder/I-am-a-Page -> 301 redirects to www.site.com/folder/i-am-a-page

Thanks. 🙂 

Posted

Some site-wide JS?

// Get the current URL
const currentUrl = window.location.href;

// Convert to lowercase
const lowercaseUrl = currentUrl.toLowerCase();

// Only update if there are uppercase letters
if(currentUrl !== lowercaseUrl) {
  // Use replaceState to update URL without reloading the page
  window.history.replaceState(null, '', lowercaseUrl);
}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...