Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 08-11-2004, 09:50 PM   #1
renee_shaeffer
Prospect
 
Join Date: Aug 2004
Posts: 3
apache mod_rewrite not working

We have the following code working on a Red Hat system, but on my OS X machine, we can't get it to work in the httpd.conf file or an .htaccess file.

Any ideas?

RewriteEngine on
RewriteRule ^classifieds/([0-9]+) /classifieds/view_classified.php?classified=$1
renee_shaeffer is offline   Reply With Quote
Old 08-12-2004, 01:57 AM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
I don't recall how at the moment, but if you read the Apache docs, I think you will find a way to turn on debugging for rewrite rules. The messages that are sent to the error.log are useful in seeing what is happening (or not).
I used this debugging option with Apache 2.0 - I'm just assuming it exists in 1.x as well.
hayne is offline   Reply With Quote
Old 08-12-2004, 04:09 AM   #3
honestpuck
Major Leaguer
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 256
Quote:
Originally Posted by renee_shaeffer
We have the following code working on a Red Hat system, but on my OS X machine, we can't get it to work in the httpd.conf file or an .htaccess file.

Any ideas?

RewriteEngine on
RewriteRule ^classifieds/([0-9]+) /classifieds/view_classified.php?classified=$1

That looks OK. First thing I'd do though is chuck a [L] at the end of the rewrite rule just to make sure. Next thing is to turn on rewrite logging by adding

RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 3

into httpd.conf - only do this for a short while as it slows down your server a lot and tends to produce a lot of results. It will give you more info than you want about how mod_rewrite is doing.

Tony
honestpuck is offline   Reply With Quote
Old 08-12-2004, 02:03 PM   #4
renee_shaeffer
Prospect
 
Join Date: Aug 2004
Posts: 3
Ok, I think I see where the problem is, but I'm not sure how to fix it... My site is under /Users/renee/sites/website and so when it does the translation of ~renee it doesn't pick up the website part of the path. So, I put the rewrite rule under:

<IfModule mod_userdir.c>
UserDir Sites/website

RewriteRule ^/homepage/(.*) /homepages/homepage\.php?user=$1[L]
RewriteRule ^/~renee/classified/([0-9]+) /~renee/classifieds/view_classified.php?classified=$1[L]

</IfModule>

Here's the output from the log:
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (3) applying pattern '^/~renee/classified/([0-9]+)' to uri
'/~renee/classified/122'
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (2) rewrite /~renee/classified/122 -> /~renee/classifieds/v
iew_classified.php?classified=122[L]
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (3) split uri=/~renee/classifieds/view_classified.php?class
ified=122[L] -> uri=/~renee/classifieds/view_classified.php, args=classified=122[L]
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (2) local path result: /Users/renee/classifieds/view_classi
fied.php
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (1) go-ahead with /Users/renee/classifieds/view_classified.
php [OK]


How do I fix this?
renee_shaeffer is offline   Reply With Quote
Old 08-12-2004, 07:31 PM   #5
honestpuck
Major Leaguer
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 256
Quote:
Originally Posted by renee_shaeffer
Ok, I think I see where the problem is, but I'm not sure how to fix it... My site is under /Users/renee/sites/website and so when it does the translation of ~renee it doesn't pick up the website part of the path. So, I put the rewrite rule under:

<IfModule mod_userdir.c>
UserDir Sites/website

RewriteRule ^/homepage/(.*) /homepages/homepage\.php?user=$1[L]
RewriteRule ^/~renee/classified/([0-9]+) /~renee/classifieds/view_classified.php?classified=$1[L]

</IfModule>

Here's the output from the log:
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (3) applying pattern '^/~renee/classified/([0-9]+)' to uri
'/~renee/classified/122'
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (2) rewrite /~renee/classified/122 -> /~renee/classifieds/v
iew_classified.php?classified=122[L]
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (3) split uri=/~renee/classifieds/view_classified.php?class
ified=122[L] -> uri=/~renee/classifieds/view_classified.php, args=classified=122[L]
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (2) local path result: /Users/renee/classifieds/view_classi
fied.php
127.0.0.1 - - [12/Aug/2004:10:55:23 -0700] [renees-laptop.local/sid#802438][rid#83a038/initial] (1) go-ahead with /Users/renee/classifieds/view_classified.
php [OK]


How do I fix this?

First, try taking off the [L] as it could be upsetting mod_userdir (I know I said put it in, but I didn't know you were in a user directory). Second, if that doesn't work do all the translation yourself, put the 'Sites/website' in the right hand side of your rule. BTW - I assume that in the path you have above the 'sites' is actually 'Sites' just as it is in your UserDir directive. I've had real problems getting mod_rewrite working properly with virtual hosting so user directories could cause similar problems.

Tony
honestpuck is offline   Reply With Quote
Old 08-12-2004, 08:36 PM   #6
renee_shaeffer
Prospect
 
Join Date: Aug 2004
Posts: 3
Thanks - we just tried creating a virtual host for the sites directory and now it is working.
renee_shaeffer is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:58 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.