I'm Floris And that's all there is to it really
30 Jan '12
[.htaccess] Force removing www and index.php
One of the tweaks to my sites is trying to add consistency, as well as trying to remove duplicate content. The first step towards doing so is by considering if you want your domain to load with or without www, and with or without index.php.
In this article I am sharing the (mod_rewrite) .htaccess code that I use.
First, let's upload an ASCII .htaccess file online by making a new file called htaccess.txt and renaming it to .htaccess
And start it with these defaults:
If you want to remove the www. from the domain, so when someone types in www.example.com, it gets automatically rewritten to example.com, use this code:
And if you want to remove index.php from the url, so when someone types in example.com/index.php, it gets automatically rewritten to example.com, use this code:
I hope this helps you tweak your site, :)
Example URL:
http://www.mrfloris.com/index.php
should now end up as:
http://mrfloris.com
In this article I am sharing the (mod_rewrite) .htaccess code that I use.
First, let's upload an ASCII .htaccess file online by making a new file called htaccess.txt and renaming it to .htaccess
And start it with these defaults:
Options +FollowSymLinks RewriteEngine On RewriteBase /
If you want to remove the www. from the domain, so when someone types in www.example.com, it gets automatically rewritten to example.com, use this code:
RewriteCond %{HTTP_HOST} ^www\.mrfloris\.com
RewriteRule (.*) http://mrfloris.com/$1 [R=301,L]
And if you want to remove index.php from the url, so when someone types in example.com/index.php, it gets automatically rewritten to example.com, use this code:
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ / [L,R=301]
I hope this helps you tweak your site, :)
Example URL:
http://www.mrfloris.com/index.php
should now end up as:
http://mrfloris.com
Latest Articles
- 2012
- Losing interest in interesting stories sometimes
- Cat candy for Sasha
- Feel Good Inc.
- Sometimes the Big Stuff Matters
- Cloud Storage
- CLI Basic Linux Commands
- CLI SSH
- Sasha 5 Years
- User Interface Design Heuristics
- Interview with Matthew from Cheers app
- iOS Clear App Tips & Tricks
- Web Application Coding Standards
- My First HTML5 Page
- The Basics of a Web Site
- CSS3 Opinion: <link> tag or @import?
- [.htaccess] Force removing www and index.php
- [php] Making a css.php
- [HTML5] Center Content
- From iOS App to the Web Site