tags:

views:

70

answers:

2

I want to redirect a user to www.domain.com/index.php if they type in either: domain.com or www.domain.com. I'm clueless about htaccess. Here's what I found but I don't know how to write an OR statement for the www. redirect

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/index.php$1 [R=301]
A: 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(domain\.com)(:80)? [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]
DirectoryIndex index.php       
order deny,allow
Gary
That works the same as my original code (doesn't redirect domain.com to www.domain.com/index.php)
decimal
+1  A: 

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^$ http://www.example.com/index.php [L,R=301]
Gumbo
It works! I didn't factor in when a user enters domain.com/index.php, it won't redirect to www.domain.com/index.php
decimal