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?
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityHere'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.