.htaccess removing www only from live site

93 Views Asked by At

Is it possible to conditionally include the rewriterule that removes www from a URL only on a live site? I have site.dev and staging.site.com and site.com setup but I only want to have one .htaccess file to keep track of. Currently my .htaccess looks like this:

RewriteEngine On

# remove index.php
RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

# remove www
# RewriteCond %{http_host} ^www\.site\.com [NC]
# RewriteRule ^(.*)$ http://site.com/$1 [R=301,NC]

on site.dev and staging.site.com. I uncomment the last two lines in site.com. If I leave the two lines uncommented on site.dev it redirects me to site.com.

UPDATE: per request below, here's the entry in httpd-vhosts.conf for this site:

NameVirtualHost *:80

<Directory "/Users/stubear/Sites/site/dev/html/">
Allow From All
AllowOverride All
</Directory>
<VirtualHost *:80>
    ServerName "site.dev"
    DocumentRoot "/Users/stubear/Sites/site/dev/html"
</VirtualHost>
0

There are 0 best solutions below