homepage Welcome to WebmasterWorld Guest from 107.20.34.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod_rewrite causes server overload / crash?
is mod_rewrite the reason for crashes?
MarkusXXL

10+ Year Member



 
Msg#: 417 posted 3:25 pm on Oct 16, 2003 (gmt 0)

Hello,

I had a problem with my server since today morning, and perhaps somebody might help me.

I am trying to set up a syntax like
http://www.example.com/index/3/
which would lead to
http://www.example.com/index.php?a=3

if there would be more values - like :
http://www.example.com/index/3/4/
- it should change it automatically to
http://www.example.com/index.php?a=3&b=4

I have also tried to get rid of the trailing slash.
My first .htaccess looked like this :


Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [L]
RewriteBase /var/www/html/~admin19/
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ /~admin19/$1.php?a=$2&b=$3&c=$4 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) /~admin19/$1.php?a=$2&b=$3&c=$4 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ /~admin19/$1.php?a=$2&b=$3 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) /~admin19/$1.php?a=$2&b=$3 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ /~admin19/$1.php?a=$2 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) /~admin19/$1.php?a=$2 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/$ /~admin19/$1.php [NE]

This caused some overload when I tried to open a php file? ( like www.xx.com/index.php , but worked fine for www.xx.com/index/ )

wel my current one looks like following :


Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [L]
RewriteBase /var/www/html/~admin19/
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ /~admin19/$1.php?a=$2&b=$3&c=$4 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ /~admin19/$1.php?a=$2&b=$3 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ /~admin19/$1.php?a=$2 [NE]
RewriteRule ^/([0-9a-zA-Z]+)/$ /~admin19/$1.php [NE]

Perhaps somebody could tell me if there are any risks, or if somehow i could make it better. Also I have now the trailing slash problem ( there HAS to be a / after the last variable )

Cheers, Markus

 

closed

10+ Year Member



 
Msg#: 417 posted 7:52 am on Oct 18, 2003 (gmt 0)

Welcome to WebmasterWorld [webmasterworld.com], MarkusXXL!

If your code works without this line:

Options +FollowSymLinks

then I wouldn't add it.

I don't really know why you have this:

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [L]

It looks to me like it doesn't do anything. I'd just delete it.

I don't think that the server choked on a request like www.xx.com/index.php when you used your first .htaccess. I think it choked on something like www.xx.com/3/index.php. The reason that would happen would be because this line would be invoked:

RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) /~admin19/$1.php?a=$2 [NE]

A check of your access log files would have helped you to see that. So the call would have been to /~admin19/3.php?a=index. If you didn't account for a case like that, then it would have choked.

I'm actually surprised that your code worked, because your RewriteRule patterns begin with:

^/

I can only get that to work in httpd.conf and not in .htaccess.

To solve the trailing slash problem, you would just need to check to see if there was a trailing slash at the end of the requested file or directory, so I would add a ? before the end anchor. For example, this line in your second .htaccess:

RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ /~admin19/$1.php?a=$2 [NE]

would be changed to:

RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /~admin19/$1.php?a=$2 [NE]

Here are some references that might be helpful:
mod_rewrite [httpd.apache.org]
Regular expressions [etext.lib.virginia.edu]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 417 posted 10:07 pm on Oct 18, 2003 (gmt 0)

MarkusXXL,

I agree with closed about the first rule doing nothing, and the solution to the missing trailing slash problem.
Also, the [NE] flag is only necessary if you intend to use the literal characters "%", "$", ",", or ";" in the substitution (the new URL). From your examples, it does not look like you need to use it here.

In addition, there is no need in this case to continue rewriting once a rule is matched and a substitution is made. Adding the [L] flag to the rules will speed up processing by stopping the rewrite engine after the first match is found and the rewrite takes place:

RewriteBase /var/www/html/~admin19/
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /~admin19/$1.php?a=$2&b=$3&c=$4 [L]
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /~admin19/$1.php?a=$2&b=$3 [L]
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /~admin19/$1.php?a=$2 [L]
RewriteRule ^([0-9a-zA-Z]+)/?$ /~admin19/$1.php [L]

I'm also not sure you need to include /~admin19/ in your RewriteBase directive, since you have included it explicitly in your RewriteRules.

Jim

MarkusXXL

10+ Year Member



 
Msg#: 417 posted 2:54 am on Oct 19, 2003 (gmt 0)

Hi Jim, Hi closed,

thanks for your replies.
To be honest I kinda took some examples and experimented around. The first statements should check if $1 is a folder ( and thatfor it has to be used as a folder, instead as $1.php )

And I think the Rewritebase is useful, since I am not checking for the source folder in the rewriterule, but for the destination folder

RewriteRule ^/([0-9a-zA-Z]+)/$ /~admin19/$1.php

So thanks for your hints, I will try now some of those and then I'll post my full .htaccess file again :)

Bye, Markus

EDIT :

That's my current .htaccess
Did I miss something? And - yes, it worked without Options +FollowSymLinks , what's so bad about it?


Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [L]
RewriteBase /var/www/html/~admin19/
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /~admin19/$1.php?a=$2&b=$3&c=$4 [L]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /~admin19/$1.php?a=$2&b=$3 [L]
RewriteRule ^/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/?$ /~admin19/$1.php?a=$2 [L]
RewriteRule ^/([0-9a-zA-Z]+)/?$ /~admin19/$1.php [L]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 417 posted 5:23 am on Oct 19, 2003 (gmt 0)

MarkusXXL,

As closed pointed out above, in .htaccess, a RewriteRule pattern that starts with "^/" is not going to match - the Rule will never be invoked. This is a difference between RewriteRules in .htaccess, and RewriteRules in httpd.conf; Rule patterns in .htaccess must not start with "^/" because the "/" is removed by the server before the pattern in the Rule is tested.

These are equivalent, depending on what file they are in:

In .htaccess :
RewriteRule ^myfile\.html$ /otherfile.html [L]

In httpd.conf :
RewriteRule ^/myfile\.html$ /otherfile.html [L]

In either context - httpd.conf or .htaccess, when testing for the same file in a RewriteCond, you would use:
RewriteCond %{REQUEST_URI} ^/myfile\.html$

Jim

MarkusXXL

10+ Year Member



 
Msg#: 417 posted 10:04 pm on Oct 19, 2003 (gmt 0)

Hi jdMorgan,

alright, I understand your point, but is it normal that it works like that from a .htaccess file?
I mean - it works - I open and link already files with
[example.com...] and also with [example.com...]

Is it normal that it works, and if - should I let it be like that, or is there something "bad" about it?

Cheers Markus

[edited by: DaveAtIFG at 10:40 pm (utc) on Oct. 19, 2003]
[edit reason] Generalized URLs [/edit]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 417 posted 6:42 pm on Oct 21, 2003 (gmt 0)

> Is it normal that it works, and if - should I let it be like that, or is there something "bad" about it?

It is not normal, but it may just be that you have a trailing slash on the path in your RewriteBase directive. I notice that the example in the mod_rewrite documentation does not include a trailing slash.

Jim

closed

10+ Year Member



 
Msg#: 417 posted 2:19 pm on Oct 22, 2003 (gmt 0)

There isn't anything wrong with having Options +FollowSymLinks, but you did write this before, MarkusXXL:

Perhaps somebody could tell me if there are any risks, or if somehow i could make it better.

And that's why I was pointing out ways in which you could write your .htaccess more efficiently.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved