Sometimes, you may need to escape special characters in URL for your website. Apache server allows you to easily escape characters using .htaccess file. Here are the steps to escape percent in Apache using .htaccess.
How to Escape Percent (%) in Apache using .htaccess
If you have percent sign in your URLs then it can stop redirects defined using RewriteRule in .htaccess. This is because percent sign has special meaning and role in rewrite rules and URL redirection. So mod_rewrite parses percent sign as a special character and causes your redirects to mess up. In such cases, proceed as follows.
1. Open .htaccess file
Open terminal and run the following command to open .htaccess file in a text editor.
$ sudo vi /var/www/html/.htaccess
2. Escape percent character
Add the following lines to .htacess file to escape percent character.
RewriteRule .* index.php/$0 [PT,B]
In the above code, the B flag ensures that percent sign remains escaped by mod_rewrite. Similarly, you can modify any other RewriteRule by adding B flag to it, to leave percent character untouched.
3. Restart Apache Server
Restart Apache server to apply changes.
$ sudo service apache2 restart
Open browser and enter URLs with percent signs in them, and they should work fine.
Also read :
How to Log POST data in NGINX
How to Read POST data in NodeJS
How to Setup Catch-All Subdomains in NGINX
How to Uninstall NodeJS, NPM in Ubuntu
How to Fix “Unable to find Socket Transport SSL” error in PHP
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.