Jun
21
2013
21
2013
Force www. prefix in URIs
For SEO, it’s best if you force WITH or WITHOUT the www. prefix for your site URL. And it’s as easy as adding a couple lines of code to your .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
#Enable these lines on prod server to require www. prefix
RewriteCond %{HTTP_HOST} ^yoururl.com
RewriteRule (.*) http://www.yoururl.com/$1 [R=301,L]
</IfModule>
Leave a comment
Recent Snippets
- htaccess : Only allow access to specific wordpress upload types if logged in
- MySQL : Query WordPress Database for Invalid Media Filenames
- PHP : Get Actual IP Address with PHP
- JavaScript : Allow Tab in Textarea
- PHP : Clean sanitized database contents on output
- htaccess : Force www. prefix in URIs
- PHP : Force File Download with Correct Content Type
- Wordpress : Disable upgrade notification