Forum Moderators: phranque

Message Too Old, No Replies

ReWrite rules appear to crash my *nix box

ReWrite rules appear to crash my *nix box

         

fuzzup

11:03 am on Jan 29, 2005 (gmt 0)

10+ Year Member



Ok I am fairly new to linux (about 6 months experience now) and setup my box from scratch with Debian on. I run my own apache webserver and keep everything fairly up-to-date. I have been trying to get a ReWriteRule working for the past couple of days (prefer to do these things myself as I learn more), and have used this forum as a constant source of knowledge. I have finally become stuck.

I was wondering if someone could point out whether something really obvious is wrong with this rule:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*) /index.php?a=$1 [L]

The idea would be that sub.abc.com/test would = sub.abc.com/index.php?a=test

Seems simple enough to me and looks like it should work, but when I launch it my browser just sits on a blank page loading. This is not the worst though, my biggest problem is that I notice with "top" (*nix prog) that apache keeps spawning more and more copies, as if the ReWriteRule is getting stuck in an infinite loop.

The help I therefore require is just some confirmation that I haven't done something really stupid in the above rules which might be causing this to happen.

Apache crashing is not good for my health, the first time it happend, after a restart of my box mysql would no longer load. I had to reinstall mysql, but not after having to also apt-get install coreutils as my df (the prog which shows disk space) was mis-reporting free space as a negative number and stopping mysql from being reinstalled.

On a similar subject, has anyone ever written any simple Windows apps that you can test ReWriteRules with. Eg, you have a blank screen which you enter your rules into and then the desired web address and it displays the outcome URL. This would be a really great app, and one I would definately use, especially as you could have step through debugging and such.

Anyway thanks for any help, and cheers for such a great forum.

Fuzzup.

fuzzup

11:06 am on Jan 29, 2005 (gmt 0)

10+ Year Member



I forgot to add that I am doing this from an .htaccess file.

Marino

12:46 pm on Jan 29, 2005 (gmt 0)

10+ Year Member



Hello,

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER}!index\.php
RewriteRule ^(.*) /index.php?a=$1 [L]

I guess that without the RewriteCond, your index.php page is stuck in the rewrite process and loops.

fuzzup

1:18 pm on Jan 29, 2005 (gmt 0)

10+ Year Member



Thanks for the reply, when I tried the above I received the following message in apache's error.log file:

/var/www/test/.htaccess: RewriteCond: bad argument line '%{HTTP_REFERER}!index\.php'

Marino

2:18 pm on Jan 29, 2005 (gmt 0)

10+ Year Member



Sorry, there was a space missing between "}" and "!" :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER}!index\.php
RewriteRule ^(.*) /index.php?a=$1 [L]

Good luck.

Birdman

3:34 pm on Jan 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, you should check the REQUEST_URI or QUERY_STRING, rather than the HTTP_REFERER. HTTP_REFERER coould very well be empty or "-".


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*) /index.php?a=$1 [L]


RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !a=
RewriteRule ^(.*) /index.php?a=$1 [L]

Don't forget to add a space after the }

[edited by: jdMorgan at 5:02 pm (utc) on Jan. 29, 2005]
[edit reason] Added persistent space using bold tags. [/edit]

Marino

5:39 pm on Jan 29, 2005 (gmt 0)

10+ Year Member



REQUEST_URI or SCRIPT_FILENAME, yes.
Why could the HTTP_REFERER be empty or equal to "-"? In case of direct request? Sorry for the question, but I'm learning, too...

Birdman

5:49 pm on Jan 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From php.net
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Marino

9:37 am on Jan 30, 2005 (gmt 0)

10+ Year Member



I see. Thanks.