mod_rewrite confusion

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
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

mod_rewrite confusion

Post 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?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: mod_rewrite confusion

Post 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. :)
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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 .
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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 ./
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post by intellivision »

D'oh! Result:

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

RewriteBase ./ caused a 500 Internal Server Error on the whole site.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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>
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post by intellivision »

It works. :D

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