Blog Details

Removing file extension via .htaccess


                                
                                    <strong>Problem:</strong>
You have the following URLs for your website:
www.wamasoftware.com/about-us.html
www.wamasoftware.com/services.html
www.wamasoftware.com/contact-us.html

However, you would like to hide file extensions from the end users, and allow them to access to the files using the following URLs:
www.wamasoftware.com/about-us
www.wamasoftware.com/services
www.wamasoftware.com/contact-us

<strong>Solution:</strong>
The solution can be achieved by using Apache’s mod_rewrite. Create an .htaccess file in your website root directory with the following content.

<del datetime="2009-01-05T12:05:38+00:00"><code>RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^.]+)\.<strong>html</strong>$ $1 [L]
# Replace html with your file extension, eg: php, htm, asp
</code></del>

<strong>Correction</strong>
<pre>RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp</pre>
                                    


Categories

Technology

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote