Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite won't work after I delete the [R] flag

please help

         

SeTsuna

7:48 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



Hi people, sorry my first post is a question

First I'll tell what i want: if I enter subdomain.example.com/2/ I want it to be rewritten to /script.php?user=subdomain&page=2

I am using this .htaccess:


Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST}!^www [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]
RewriteRule ([0-9]+)? /script.php?user=%1&page=$1 [R=301,L]

This works fine, but i don't want it to be redirected, I want to keep the original url (subdomain.example.com/2/). But when I remove the R flag from the rewriterule I get a 500 error, what am I doing wrong?

Thanks!

jdMorgan

8:08 pm on Oct 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SeTsuna,

What does your server error log say when you get the 500-Server Error response? Knowing that would be very helpful.

Jim

SeTsuna

5:32 pm on Oct 17, 2004 (gmt 0)

10+ Year Member



I can't seem to find my error logs (i sent a mail to my host for help on that), but the code of my htaccess is ok?

jdMorgan

3:29 am on Oct 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's possible that the lack of start and end anchors and the trailing "?" of your RewriteRule pattern were creating a recursive rewrite, since /script.php would match that pattern as well. I'd suggest:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^([0-9]+)/$ /script.php?user=%1&page=$1 [L]

This will rewrite only requests for URLs of the form "/<one or more digits>/" and not rewrite requests for anything else.

Also, the [NC] flags should not be needed, as domains are lowercase-only as sent by browsers.

If you do not have access to your error log file, you need a better host. I cannot recommend using mod_rewrite on a server that limits your access to basic troubleshooting tools.

See the regular-expressions tutorial cited in our charter [webmasterworld.com] for more information on regular-expressions pattern matching.

Jim

SeTsuna

9:28 am on Oct 18, 2004 (gmt 0)

10+ Year Member



thanks! the only thing that i needed to ad was a "?":

[code]RewriteRule ^([0-9]+)/?$ /script.php?user=%1&page=$1 [L][code]

it works now :)