Forum Moderators: phranque
The code I am using in my .htaccess is:
Options +FollowSymLinks
rewriteEngine on
rewriteCond %{HTTP_HOST} .
rewriteCond %{HTTP_HOST}!^example\.com
rewriteRule (.*) http://www.example.com/$1 [R=301,L]
I am receiving a 500 error and suggestions point to the FollowSymLinks as my issue but it is clearly set.
On a separate but similar note, my symbolic links aren't fully working, I am linking to an images directory and only the JPEGs appear to be linking across, not the GIFs...could my hosting have the symbolic links restricted? If so, could that be causing my rewrite issue?
Any help would be greatly appreciated. As you can gather from above, i am working in a hosted environment and do not have access to the conf file.
THANKS!
[edited by: jdMorgan at 1:41 am (utc) on Sep. 21, 2005]
[edit reason] Example.com. [/edit]
Welcome to WebmasterWorld!
You code has a logic flaw, and possibly a syntax error in it as well.
As written, it will redirect requests for all domains that are NOT "example.com" to "www.example.com" -- and that will lead to an infinite loop, since "www.example.com" is not "example.com". This redirection will continue until either the client browser or the server 'times out' and aborts the request.
The possible syntax error is that a space is required between "}" and "!" in the RewriteCond. However, posting on this forum often removes that space, so I can't tell if your code has this error or not.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
Thanks for the response, I am almost there, one issue, well two. First, I got it to work but had to remove the $1...with it I received a 404 error. This is fine except all pages will redirect to www.example.com if they have anything else in the URL....so first, how can i switch it to look for something that is there, rather than not existing, I took out the! but that didn't do the trick. Secondly, I need the $1 working, any idea there?
Again thanks!
Here is the code now.
Options +FollowSymLinks
rewriteEngine on
rewriteCond %{HTTP_HOST} .
rewriteCond %{HTTP_HOST}!^www\.example\.com
rewriteRule (.*) http://www.example.com/ [R=301,L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Jim