Forum Moderators: phranque

Message Too Old, No Replies

A bit of trouble with mod rewrite

mod_rewrite issues for SEF urls

         

jdilegge

11:27 pm on Jun 8, 2011 (gmt 0)

10+ Year Member



I am having some trouble here. I coded a twitter / facebook hybrid and the wall is working but when ajax refreshes the wall upon posting I get this in my error log and the browser says that the page expired:


[Wed Jun 08 19:26:01 2011] [info] [client #*$!#*$!xx] (32)Broken pipe: core_output_filter: writing data to the network
[Wed Jun 08 19:26:02 2011] [info] [client #*$!#*$!xx] (104)Connection reset by peer: core_output_filter: writing data to the network



Concerning that error, I do have this in my apache includes file:

EnableSendfile off


Does anyone see what I am doing wrong? The URLs are in fact working, except I have this error showing only when ajax is posting data to query string.



<IfModule mod_rewrite.c>
RewriteEngine On

# put trailing slash up
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# check for existing file/dir
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteBase /twit/

# actions rewrite *works fine
RewriteRule actions/(.*)/$ actions.php?action=$1


RewriteCond %{REQUEST_URI} !^actions/ [OR]
RewriteCond %{REQUEST_URI} !^wall/ [OR]
RewriteCond %{REQUEST_URI} !^system/ajax

# create domain.com/username
# and domain.com/username/alphaNumericDashUnderscore/

RewriteRule ^([A-Za-z0-9-_]+)/$ index.php?who=$1
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/$ index.php?who=$1&where=$2

</IfModule>

jdilegge

11:27 pm on Jun 8, 2011 (gmt 0)

10+ Year Member



lol I put a bunch of X's in a row and the word filter picked it up.

jdilegge

11:34 pm on Jun 8, 2011 (gmt 0)

10+ Year Member



The problem comes when the ajax code brings up the wall after oyu added a new message. THen upon posting the message a second time it seems it is trying to redirect too many times perhaps?

g1smd

11:38 pm on Jun 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Several things need to be tidied up.

Add the [L] flag to every rule.

Your second set of RewriteCond lines need a RewriteRule to be immediately following them.

The RewriteBase directive should be "up top".

Your third set of RewriteCond lines affect only the single rule that follows them.

The final RewriteRule has NO attached RewriteCond lines.

Place a blank line after every RewriteRule directive to make the code more clear to read.

jdilegge

11:41 pm on Jun 8, 2011 (gmt 0)

10+ Year Member



In firefox web console I got this. The first status message I added, did ad and refreshed the wall. Then the second redirected to the wall with # at the end.

[19:39:41.174] Unknown property 'zoom'. Declaration dropped. @ [onlypeek.com...]
[19:39:33.518] POST [onlypeek.com...] [HTTP/1.1 200 OK 235ms]
[19:39:33.846] Unknown property 'whitespace'. Declaration dropped. @ [onlypeek.com...]
[19:39:33.868] Expected declaration but found '530px'. Skipped to next declaration. @ [onlypeek.com...]
--
[19:39:41.006] POST [onlypeek.com...] [HTTP/1.1 200 OK 640ms]
[19:39:41.168] Error in parsing value for 'overflow'. Declaration dropped. @ [onlypeek.com...]
[19:39:41.171] Error in parsing value for 'padding'. Declaration dropped. @ [onlypeek.com...]
[19:39:41.173] Error in parsing value for 'filter'. Declaration dropped. @ [onlypeek.com...]

jdilegge

11:45 pm on Jun 8, 2011 (gmt 0)

10+ Year Member



Thanks, much appreciated! How does this look? Since my urls are working, perhaps the query string is not the issue but instead is the PHP that the ajax is sending data too.

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /twit/

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^actions/$ [OR]
RewriteRule actions/(.*)/$ actions.php?action=$1 [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^actions/$ [OR]
RewriteCond %{REQUEST_URI} !^wall/$ [OR]
RewriteCond %{REQUEST_URI} !^system/ajax/$
RewriteRule ^([A-Za-z0-9-_]+)/$ index.php?who=$1 [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^actions/$ [OR]
RewriteCond %{REQUEST_URI} !^wall/$ [OR]
RewriteCond %{REQUEST_URI} !^system/ajax/$
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/$ index.php?who=$1&where=$2 [L]
</IfModule>

g1smd

12:06 am on Jun 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is at least one [OR] that is not needed.

The second (.*) should be ([^/]+) too.

Your code looks a lot better, but has a HUGE inefficiency built in.

Most requests will invoke SEVEN reads of the hard drive checking to see if the request is a file or a folder, or not. This will massively slow down your server. Make sure the -f and -d checks are the LAST checks per rule, not the first.

[A-Za-z] simplifies to [A-Z] when you also add the [NC] flag. Parses much quicker too.

The REQUEST_URI value begins with a leading slash I believe, so without it none of your rules will match a real request.

Some of the RewriteCond lines are either incorrect or are not needed. For example, you test for "something/something/" in the last rule and then the condition says "not for exactly 'something'" and this condition can never match. Either remove the END anchor to make the condition "begins with 'something'", or else remove the condition completely.