Answers.Body: <p>Here's what I'm using:</p>
  
  <pre><code># Remove the www from the URL
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  
  # Exclude root files
  RewriteCond $1 !^(favicon\.ico|favicon\.png|fb_share\.jpg|apple-touch-icon\.png|apple-touch-icon-precomposed\.png|index\.php|robots\.txt) [NC]
  
  # Exclude asset folders
  RewriteCond $1 !^(assets|uploads)/ [NC]
  
  # Remove index.php
  RewriteRule ^(.*)$ /index.php/$1 [L]
  </code></pre>
  
  <p>You could also set up a CNAME record from www.domain.com to domain.com in your DNS.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-04T17:52:04.593Z
Answers.Text: Thanks for the tip. Is there a best practice for pointing non-www to www or vice versa? Do I need the CNAME if I have my A records set up as described in my original question?
Answers.UserDisplayName: blairrorani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-04T17:58:55.327Z
Answers.Text: And should I wrap <IfModule mod_rewrite.c> around all that code in .htaccess?
Answers.UserDisplayName: blairrorani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-04T18:15:45.703Z
Answers.Text: This broke the absolute links to my style sheets. What should my siteURL be set to?
Answers.UserDisplayName: blairrorani
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-04T19:03:11.763Z
Answers.Text: I think it's better to have an A-record for the domain pointed to the IP, and a CNAME for www.domain.com to domain.com. BUT, don't take my word for it.
  
  If you want to make sure the htaccess file works on servers that doesn't have the rewrite module installed, you could wrap it in the if, but it's not necessary.
Answers.UserDisplayName: André Elvan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-04T19:07:05.047Z
Answers.Text: I forgot to say, but this rule rewrites everything except the files that are excluded (the two rewrite conditions). In my case I have all my assets in /assets and uploaded files in /uploads. If you have files in other locations, you need to add them to the rule.
Answers.UserDisplayName: André Elvan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-04T09:41:50.467Z
Answers.LastActivityDate: 2014-09-04T09:41:50.467Z
Answers.UserDisplayName: André Elvan
Body: <p>I want to point any domain.com/page to the www.domain.com/page without showing index.php in my urls. </p>
  
  <p>I have a www and non-www A record pointing to an IP address.</p>
  
  <p>How do I set up my .htaccess file to do this?</p>
  
Tags: <url>
Title: How should I setup my .htaccess file
ThreadText: # How should I setup my .htaccess file
  
  (Asked by: username_0 on 2014-09-04)
  
  I want to point any domain.com/page to the www.domain.com/page without showing index.php in my urls.
  
  I have a www and non-www A record pointing to an IP address.
  
  How do I set up my .htaccess file to do this?
  
  **Tags:** url
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-09-04. Score: 1
  
  Here's what I'm using:
  
  ```
  # Remove the www from the URL
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  
  # Exclude root files
  RewriteCond $1 !^(favicon\.ico|favicon\.png|fb_share\.jpg|apple-touch-icon\.png|apple-touch-icon-precomposed\.png|index\.php|robots\.txt) [NC]
  
  # Exclude asset folders
  RewriteCond $1 !^(assets|uploads)/ [NC]
  
  # Remove index.php
  RewriteRule ^(.*)$ /index.php/$1 [L]
  
  ```
  
  You could also set up a CNAME record from www.domain.com to domain.com in your DNS.
  
  > **Comments:**
  > **username_0**: Thanks for the tip. Is there a best practice for pointing non-www to www or vice versa? Do I need the CNAME if I have my A records set up as described in my original question?  
  > **username_0**: And should I wrap <IfModule mod_rewrite.c> around all that code in .htaccess?  
  > **username_0**: This broke the absolute links to my style sheets. What should my siteURL be set to?  
  > **username_1**: I think it's better to have an A-record for the domain pointed to the IP, and a CNAME for www.domain.com to domain.com. BUT, don't take my word for it.  If you want to make sure the htaccess file works on servers that doesn't have the rewrite module installed, you could wrap it in the if, but it's not necessary.  
  > **username_1**: I forgot to say, but this rule rewrites everything except the files that are excluded (the two rewrite conditions). In my case I have all my assets in /assets and uploaded files in /uploads. If you have files in other locations, you need to add them to the rule.  
  
  ---
  
  