Forum Moderators: phranque

Message Too Old, No Replies

Rewrite giving 500 error

         

pmessana

1:06 am on Sep 21, 2005 (gmt 0)



Alright, i have read a bunch of posts and thought that I finally figured out the redirect, basically, I am trying to redirect example.com -> www.example.com as I am having issues switching between http and https in IE (no problems in FireFox).

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]

jdMorgan

1:40 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



pmessana,

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

pmessana

2:05 am on Sep 21, 2005 (gmt 0)



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]

jdMorgan

2:12 am on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming that the code you tested was this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

The it should work as you intended. If that does not work, it's either a misconfiguration problem, or a bad install of Apache or the POSIX regular-expressions library.

Jim