ModRewrite Help

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

ModRewrite Help

Post by shiznatix »

I have this line for a mod rewrite rule:

Code: Select all

RewriteRule ^([a-z0-9-.]+)/offers$ rooms.php?_view=offers&fk_room=$1 [QSA]
but it works on 1 server but on another server it gives an internal server error. Can anyone tell me what is wrong with it? if I remove the - character to find it goes just fine but I need to be able to match again it.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Try setting a RewriteBase, and checking your errorlog. One of two things is going wrong. It's either rewriting to the wrong directory, or it can't handle your regex (though, the regex looks too simple for that to be a problem).
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

That didn't work. Here is my whole .htaccess file:

Code: Select all

RewriteEngine on

RewriteBase /

ErrorDocument 404 /file_not_found.php

RewriteRule ^poker-forum$ poker-forum/ [L,QSA]
RewriteRule ^poker-forum/$ poker-forum/ [L,QSA]

RewriteRule ^([a-z_-]+)$ $1.php
RewriteRule ^([a-z_-]+)/$ $1.php

#RewriteRule ^news/([a-zA-Z0-9_-\s]+)$ news.php?fk_title=$1 [L,QSA
##RewriteRule ^news/([a-zA-Z0-9_-\s]+)/$ news.php?fk_title=$1 [L,QSA]

RewriteRule ^bonus-offers/signup$ bonus-offers.php?_view=signup [QSA]
RewriteRule ^bonus-offers/signup/$ bonus-offers.php?_view=signup [QSA]

##RewriteRule ^([a-z0-9-.]+)/offers$ rooms.php?_view=offers&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/offers/$ rooms.php?_view=offers&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/info$ rooms.php?_view=info&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/info/$ rooms.php?_view=info&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/network$ rooms.php?_view=network&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/network/$ rooms.php?_view=network&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/signup$ rooms.php?_view=signup&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/signup/$ rooms.php?_view=signup&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/confirmed$ rooms.php?_view=confirmed&fk_room=$1 [QSA]
##RewriteRule ^([a-z0-9-.]+)/confirmed/$ rooms.php?_view=confirmed&fk_room=$1 [QSA]

RewriteRule ^([a-z_-]+)/([a-z_0-9]+)$ $1.php?_view=$2 [QSA]
RewriteRule ^([a-z_-]+)/([a-z_0-9]+)/$ $1.php?_view=$2 [QSA]

RewriteRule ^([a-z_-]+)/([a-zA-Z0-9_-]+)$ $1.php?fk_title=$2 [QSA]
RewriteRule ^([a-z_-]+)/([a-zA-Z0-9_-]+)/$ $1.php?fk_title=$2 [QSA]

RewriteRule ^([a-z_-]+)/([0-9]+)$ $1.php?fk_entry=$2 [QSA]
RewriteRule ^([a-z_-]+)/([0-9]+)/$ $1.php?fk_entry=$2 [QSA]

RewriteRule ^([a-z_-]+)/([a-z_]+)/([0-9]+)$ $1.php?_view=$2&fk_entry=$3 [QSA]
RewriteRule ^([a-z_-]+)/([a-z_]+)/([0-9]+)/$ $1.php?_view=$2&fk_entry=$3 [QSA]
If I uncomment any of those lines that are commented out, it will give me an internal server error no matter what. Is there something that could be causing this?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Did you check the error log?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

superdezign wrote:Did you check the error log?
yes sorry, I have this error:

[Thu Aug 9 12:42:44 2007] [alert] [client 84.112.182.59] /home/rakeback/public_html/.htaccess: RewriteRule: cannot compile regular expression '^news/([a-zA-Z0-9_-\\s]+)$'\n

which is showing me that it is double escaping the \s (single space) but even if I just put a blank space it goes down so what can I put instead of the \s?

As for the other sections I get:

[Thu Aug 9 12:45:41 2007] [alert] [client 87.119.160.4] /home/rakeback/public_html/.htaccess: RewriteRule: cannot compile regular expression '^([a-z0-9-.]+)/offers$'\n

but I dont see what is wrong with it.
Post Reply