Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite working locally not remote

500 internal server error

         

andytwiz

9:43 pm on Mar 27, 2005 (gmt 0)

10+ Year Member



Hi

Can someone tell me whats wrong with this code? It works locally but gives a 500 error on my server (with nothing in the error log)

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI}!index\.php$

RewriteRule ^([^/]+)/stylesheets/([^/]+)/([^/^?]+)$ /index.php?site=$1&template=$2&stylesheet=$3

RewriteRule ^([^/]+)/(.*)$ /index.php?site=$1 [L]

Thanks

jdMorgan

6:17 am on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd recommend that you try something simpler first:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^foo\.bar$ /index.php [L]

If you request "foo.bar" from your server and see your "index.php" output as the page content, then the problem is with your code. If not, then maybe you can't run mod_rewrite on your remote server.

Jim

andytwiz

9:32 am on Mar 28, 2005 (gmt 0)

10+ Year Member



Thanks. the code you supplied works fine. Each of my rules also works fine on their own.

The problem is only when I try to use them together...(?)

jdMorgan

7:00 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just a thought:

You know that your RewriteCond only applies to the first RewriteRule that follows it, right?

You may be doing an "infinite loop" on the second rule if index.php is requested from any subdirectory.

Also, add an [L] flag to all RewriteRules, unless you have a reason not to.

Jim

andytwiz

1:28 am on Mar 29, 2005 (gmt 0)

10+ Year Member



hi cheers again for the reply.

1) i didnt know the RewriteCond only applies to the next rule - how do you make it apply to all following rules?

2) I tried with [L] - no difference.

3) I checked and there is no .htaccess in the subfolder sending it into an infinite loop.

What's confusing is each of these RewriteRules work on their own and both together on my localhost but not both togehter on the remote server...

jdMorgan

6:38 am on Mar 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> 1) i didnt know the RewriteCond only applies to the next rule - how do you make it apply to all following rules?

You don't. The easiest solution is to repeat the RewriteCond for each rule.

> 2) I tried with [L] - no difference.

Use [L] anyway, unless you *know* you can't use it. Otherwise the output of each rewrite is processed by all the following rewrites, which is usually a hug waste of time.

> 3) I checked and there is no .htaccess in the subfolder sending it into an infinite loop.

Yeah, probably not a problem, as long as you have a RewriteCond on each rule.

Jim

andytwiz

11:20 am on Mar 29, 2005 (gmt 0)

10+ Year Member



Ahaa!
Putting the Cond before each line fixes the problem! Cheers! :)