This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show Sometimes it’s important to remove -or hide- the file extension of scripts you use. Security by obscurity might be that reason, if you don’t want others to know what script language you are using for your website, or for
static site hosts. This example will hide the Why the need to hide file extensions in URL’s?I am no fan of security by obscurity, and I have never encountered this as the result outcome of a security scan.
There is also no benefit for SEO, for as far as I know. You can however, use this technique to shorten URL’s a bit. It does shave off four to five characters from the URL (“.php”, “.html”, “.aspx”). And some say a website performs faster because a web server can match URL’s without extensions to folders (directories) faster than URL’s with an extension to a file. Some say. I have no data or further information on this. Here is an IIS URL Rewrite Module example for you to hide .php extension in URL’s. This technique is also known as Multiviews or Content Negotiation in Apache, and others call it extensionless URLs. See below for an example to use with .htaccess in IIS. About MultiViews, or content negotiation:
Put the following rewrite in a IIS’ URL Rewrite Module adds the
For requests already containing a .php extensionA more extended example is to redirect all requests with .php in the URL to their extension-less variant. So when a visitor comes in through Our Rewrite rule maps that final request back to index.php without displaying the extension.
Always test such examples before putting it into production. Emulate Apache Multiviews in IIS using a .htaccess file and Helicon ApeIf you use .htaccess in IIS you can create the same Multiviews effect to hide the .php extension. For this to happen you have to declare a few rewrite conditions and rewrite rules ( Multiviews .htaccess example
.htaccess rules explanation: The pattern
The replacement
Finally, a rule is added that hides the .php extension. This prevents a search engine from finding duplicate content, and thus prevents a penalty for your site’s position in the search results. There are other ways too. Remove .php extension with .htaccess from URLsTo remove the .php extension from a URL with .htaccess, you can save the following in a new .htaccess file:
Or use MultiViews:
This removes the extension making the URLs more user and -some say- SEO search engine friendly. Use what works best for you, and add a canonical meta tag in your HTML head to avoid duplicate content (where appropriate). Loading time: 107 queries, 0.395 seconds using 28022016 bytes memory. Peak memory usage: 28883776 bytes. The . html extension can be easily removed by editing the . htaccess file. However, if the website contains PHP code, that code is not visible, because all the PHP code is executed on the server before the website is sent to a browser. All the browser ever receives is the result of the PHP embedded in the HTML. |