Forum Moderators: phranque
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
It was the only text in my .htaccess file and I got the following when trying to access my page:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, support@supportwebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
--------------------------------------------------------------------------------
Apache/1.3.33 Server at ["example.com"] Port 80
# For use in document-root .htaccess
# Enable mod_rewrite (Required on some but not all server configurations; May cause an error if not needed)
Options +FollowSymLinks
# Turn on the rewriting engine
RewriteEngine on
# If request Host header is non-blank (HTTP/1.0 requests don't send this header and can't be redirected based on it)
rewritecond %{http_host} .
# And if requested domain is NOT the canonical domain
rewritecond %{http_host} !^www\.example\.com
# Redirect to requested page in canonical domain
rewriterule (.*) http://www.example.com/$1 [R=301,L]
I still get an error and can't load the site; this time with the following in the log:
Mon Jun 2 22:38:44 2008] [alert] [client IP address deleted for forum posting] /var/chroot/home/content/b/e/s/[example]/html/.htaccess: Invalid command '\xef\xbb\xbf#', perhaps mis-spelled or defined by a module not included in the server configuration
Invalid command '\xef\xbb\xbfOptions'
Your .htaccess file is apparently corrupt, or at least invalid.
Use a plain-text editor, set to output US-ASCII format (or UTF-8 without the character-set header) to edit your .htaccess file. Use Windows NotePad, for example, not a fancy editor or word processor program.
Jim
Options +FollowSymLinks
RewriteEngine on
rewritecond %{http_host} .
rewritecond %{http_host} !^www\.example\.com
rewriterule (.*) http://www.example.com/$1 [R=301,L]
When I type "example.com" in my browser's address bar, it does not resolve to www.example.com. Why?
You should end-anchor the domain name in your RewriteCond, and I recommend that (in order to ensure portability) you DO NOT feel free to substitute lowercase variable names for uppercase. e.g. %{HTTP_HOST} is the variable name given in the documentation.
Jim