Page 1 of 1

mod_rewrite confusion

Posted: Mon Jan 16, 2006 12:12 pm
by intellivision
I'm trying to rewrite
domain.com/product_reviews.php?mode=1&id=44
into
domain.com/product_reviews/mode/1/id/44/
I'm working in domain.com/.htaccess

I'm getting a "The requested URL /product_reviews/mode/1/id/44/ was not found on this server."

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
Options +FollowSymLinks
RewriteRule product_reviews/mode/(.*)/id/(.*) product_reviews.php?mode=$1&id=$2
RewriteRule product_reviews/mode/(.*)/id/(.*)/ product_reviews.php?mode=$1&id=$2
</IfModule>
What am I doing wrong?

Re: mod_rewrite confusion

Posted: Mon Jan 16, 2006 1:10 pm
by foobar
intellivision wrote:I'm trying to rewrite
domain.com/product_reviews.php?mode=1&id=44
into
domain.com/product_reviews/mode/1/id/44/
No you're not. It's the other way around. :wink:

First, I'd get rid of all the unnecessary stuff and reformulate the regex pattern:

Code: Select all

RewriteEngine on

#Make webroot working directory
RewriteBase /

#One rule instead of two...
RewriteRule product_reviews/mode/(\d+)/id/(\d+)(/)?$ product_reviews.php?mode=$1&id=$2
That should throw a 500 error if you don't have mod_rewrite installed.
Further, it only allows integers to be passed as mode and id.

If this code works, you can put the Options and your other RewriteRule back in. :)

Posted: Mon Jan 16, 2006 1:36 pm
by intellivision
Thanks.

domain.com/product_reviews/mode/1/id/45/ = 404 error

The following is the entire .htaccess file, and I checked it via ssh/pico to make sure no strange characters are getting in it (none):

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on

#Make webroot working directory 
RewriteBase / 

#One rule instead of two... 
RewriteRule product_reviews/mode/(\d+)/id/(\d+)(/)?$ product_reviews.php?mode=$1&id=$2 
</IfModule>
From my host -- Dreamhost:
We run a default apache installation, so
anything that works there, should work here.
So I'm sure the module is there. Here's more proof: http://wiki.dreamhost.com/index.php/Mod_rewrite .

Posted: Mon Jan 16, 2006 2:01 pm
by foobar
Have you tried getting rid of the <IfModule> tags?

Also, can you post where on the server relative to the webroot your account resides?
(This can be done via getcwd() in a PHP script.)

Furthermore, can you post what exactly is in your root directory? Such as a screenshot of the directory listing.

Posted: Mon Jan 16, 2006 2:29 pm
by intellivision
Tags removed, no change.

Code: Select all

<? getcwd();
echo('test'); ?>
results in nothing but the word 'test', in both screen and source. Grrr. I have no idea where the webserver is in relation to my shared hosting root directory.

Here's the root directory shot:
Image

Posted: Mon Jan 16, 2006 3:12 pm
by foobar
intellivision wrote:

Code: Select all

<? getcwd();
echo('test'); ?>
results in nothing but the word 'test', in both screen and source. Grrr. I have no idea where the webserver is in relation to my shared hosting root directory.
Try this instead:

Code: Select all

<?php echo getcwd(); ?>
You might want to do the following change in the .htaccess file:

Code: Select all

RewriteBase ./

Posted: Mon Jan 16, 2006 3:48 pm
by intellivision
D'oh! Result:

/home/.eamonblendersybian/matthew1/matthe/domain.com

RewriteBase ./ caused a 500 Internal Server Error on the whole site.

Posted: Tue Jan 17, 2006 12:25 am
by redmonkey
\d is most likely the culprit, you could try something along the lines of....

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteBase /

RewriteRule product_reviews/mode/([0-9]+)/id/([0-9]+)(/)?$ product_reviews.php?mode=$1&id=$2 
</IfModule>

Posted: Wed Jan 18, 2006 12:16 am
by intellivision
It works. :D

Thanks to both of you for your help with this. Much appreciated.