php - Remove whitespace in URL and make everything lowercase with htaccess
Get the solution ↓↓↓I have whitespaces (i.e. %20) and Upppercase in my URLs that I need to remove with an htaccess rule
My web site allow to analyze Account Instagram analytics, so may happen that user wrote (as example) "kourtneykardash" , "kourtney kardash", or "Kourtney Kardash" to check report.
Url is resolved as:
https://www.EXAMPLE.com/report/kourtneykardash (correct version)
or
https://www.EXAMPLE.com/report/kourtney kardash (wrong version, with whitespace)
or
https://www.EXAMPLE.com/report/Kourtney Kardash (wrong version, with whitespace and uppercase)
All of three, of course, show the same report, but I would like to have only the exact version like for the Instagram account username, without any spaces or Uppercase characters. (this will solve too any canonical issue or duplicate contents issue..)
Actually my .htaccess is this:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^page=([\w/-]*)
RewriteRule ^index\.php$ /%1 [QSD,R=302,L]
Options All -Indexes
RewriteEngine On
RewriteRule ^sitemap.xml sitemap.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
How can I edit my .htaccess file to remove whitespace in URL and make every character lowercase?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: property [id] does not exist on this collection instance.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.