I need to capture URLs that have any characters that could be encoded. For example +, {space}, [,] etc. I tired doing the following but did not work –
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} ^(.*)(\s|\+|\%)+(.*)$
RewriteRule ^(.*)$ /content/my-rewrite-redirect.php [L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://mydomain.com/content/$1$1 [QSA,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://mydomain.com/content/$1 [QSA,L]
(\s|+|\%) – tried this to capture space characters and any character that has been encoded in the URL but it does not capture URLs like – http://mydomain.com/vertical%5B1%5D.jpg
Thansk for your time.
The problem you’re running into is likely that URLs are decoded by Apache before getting to htaccess. You should try instead of searching for encoded characters, to create a regex that searches for any characters that WOULD BE URL-encoded.
e.g.:
Of course, there will be many more characters that qualify… this is just an example