Site icon Web Niraj

Using .htaccess Files to hide Query Variables

I came into a recent issue where I wanted to hide ?id=xx from the query string of a URL so I could use a single Facebook Comment Plugin with different data. I fixed the issue by using a few lines of code in a .htaccess file.

RewriteBase /
RewriteRule ^file-([0-9]+)\.php$ /some_directory/files.php?id=$1 [L]

The code above simply points URLs like file-1.php to a single PHP file, but modifies the query string to make files.php?id=1. This means I can hide the query string and make the Facebook Comment Plugin think each page is unique. Since Facebook doesn’t allow query strings in the plugin, this is a elegant solution to make it work.

Exit mobile version