Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite error 500

         

RVB_Pix

11:08 am on Aug 26, 2004 (gmt 0)

10+ Year Member



Hi,
I'm trying to write a simple rewrite in an htacces file found in the root directory of my site, and all I get is an internal server error 500.
I know mod rewrite is activated on the server and works for some, for example

RewriteEngine On
RewriteBase /
RewriteRule ^user1(.*)$ /showgallery.php?cat=500&ppuser=1
RewriteRule ^user2(.*)$ /showgallery.php?cat=500&ppuser=2
RewriteRule ^user3(.*)$ /showgallery.php?cat=500&ppuser=23

however, the following results in the 500 error

RewriteEngine On
RewriteCond %{HTTP_host}!^www\.mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]

Any ideas why?

Span

11:13 am on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,
Welcome to the Forums.

Maybe this throws the error: HTTP_host should be all uppercase HTTP_HOST

RVB_Pix

11:56 am on Aug 26, 2004 (gmt 0)

10+ Year Member



Thanks for the welcome and the quick response.

It worked but I don't see it getting rewritten from domain.com to www.domain.com in the browsers address bar. Or am I wrong in thinking it should?

jdMorgan

3:26 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the address bar should be updated, since this code invokes an external redirect.

Make sure you have a space ahead of the "!" in the RewriteCond.
Also, you should test to make sure the HTTP_HOST variable is not empty, in order to prevent putting true HTTP/1.0 user-agents into an infinite redirection loop, and omit the end-anchor from the pattern in case a port number is appended to the HTTP_HOST:


RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} [b]![/b]^www\.mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=permanent,L]

Jim

RVB_Pix

4:42 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



Thanks Jim, but for some reason it's not working for me

RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mysite\.com
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]

There's no server error just not updating the address bar :(

jdMorgan

10:33 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know why that wouldn't work if you've got other rules in the same file that work.

There are some strange things that can interfere with mod_rewrite, things like incorrect LoadModule order and such, but it's hard to tell from what you've posted what the problem might be.

Jim

RVB_Pix

7:33 am on Aug 27, 2004 (gmt 0)

10+ Year Member



It's seems that the modules load in the correct order with mod rewrite before the PHP one, unless there is more to it than that. :(

LoadModule rewrite_module libexec/mod_rewrite.so
LoadModule php4_module libexec/libphp4.so
LoadModule bwlimited_module libexec/mod_bwlimited.so
LoadModule bytes_log_module libexec/mod_log_bytes.so
LoadModule auth_passthrough_module libexec/mod_auth_passthrough.so
#LoadModule gzip_module libexec/mod_gzip.so

ClearModuleList
AddModule mod_env.c
AddModule mod_log_config.c
AddModule mod_mime.c
AddModule mod_negotiation.c
AddModule mod_status.c
AddModule mod_include.c
AddModule mod_autoindex.c
AddModule mod_dir.c
AddModule mod_cgi.c
AddModule mod_asis.c
AddModule mod_imap.c
AddModule mod_actions.c
AddModule mod_userdir.c
AddModule mod_alias.c
AddModule mod_rewrite.c
AddModule mod_access.c
AddModule mod_auth.c
AddModule mod_so.c
AddModule mod_setenvif.c
<IfDefine SSL>
AddModule mod_ssl.c
</IfDefine>
AddModule mod_frontpage.c
AddModule mod_php4.c
AddModule mod_bwlimited.c
AddModule mod_log_bytes.c
AddModule mod_auth_passthrough.c
#AddModule mod_gzip.c

Is there something else I should look for in the httpd file?

jdMorgan

1:29 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, modules execute in the reverse order from their load order. Notice that authorization, loaded last, is almost always the first thing processed for a request. I'd suggest moving php above mod_rewrite, and seeing if that helps.

Jim

RVB_Pix

6:28 am on Aug 28, 2004 (gmt 0)

10+ Year Member



Jim,

For some reason overnight the rewrite rules ended up working even without changing the module loading order. I don't understand, but anyway it's working perfectly.
Thanks a lot for your help and precious information.

Stephen

jdMorgan

4:47 pm on Aug 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Always remember to flush your browser cache (temporary internet files) and any other caches (e.g local proxy cache if you have one) on your end before testing any change to your redirection code. You probably had a cached copy of the "wrong" result, so the request was never sent to your server. If a request is not sent to your server, then of course your server can't change the response.

Jim