|
|
#1 |
|
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 |
|
|
|
|
|
#2 |
|
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. |
|
|
|
|
|
#3 | |||||||||||||||||||||||
|
Major Leaguer
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 256
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#4 |
|
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? |
|
|
|
|
|
#5 | |||||||||||||||||||||||
|
Major Leaguer
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 256
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#6 |
|
Prospect
Join Date: Aug 2004
Posts: 3
|
Thanks - we just tried creating a virtual host for the sites directory and now it is working.
|
|
|
|
![]() |
|
|