Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Dunmail

macrumors regular
Original poster
Mar 27, 2009
224
4
Skipton, UK
I'm having a bit of fun :eek: with rewrites on OS X Lion and I can't get my head around it.

Basically I'm creating an MVC app in a subfolder of my development site (under the default Sites folder in my home folder) and the rewrite is changing this:

PHP:
http://localhost/~dunmail/dunmail/app/test

to
PHP:
http://localhost/Users/dunmail/Sites/dunmail/test/

When it should be

PHP:
http://localhost/Users/dunmail/Sites/dunmail/index/test

If I actually type the latter in to the address bar then the correct file appears so the app side would appear to be working as far as this is concerned.

The .htaccess is:

Code:
Options +FollowSymLinks
rewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index/$1 [L,QSA]

I've changed httpd.conf and dunmail.conf to set AllowOverride All but that hasn't improved things.

Does anyone have any clues as to what I need to modify - I'm going round in circles here!
 
Did you restart Apache? I think you need to disable then re-enable "Web Sharing" for your .htaccess changes to take effect.
 
Your rule looks fishy to me. Try this. If it doesn't work, maybe .htaccess isn't being used.

Code:
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index/%1 [L]

EDIT: After looking it up I guess I'm just more familiar with %1 vs $1 as used when its the same rule.
I'd suspect the .htaccess file is not being used. Try what Yvan256 said, otherwise make sure Allow Overrides are turned on.
 
Last edited:
As I said in the original post - AllowOverride is set to All. And I have restarted Apache - several times. :eek:
 
As I said in the original post - AllowOverride is set to All. And I have restarted Apache - several times. :eek:

Then mod_rewrite isn't on/working.

Or your .htaccess isn't being used.

Put some gibberish like 'testing 12344' into the .htaccess and see if that folder gets a server error.
 
I'd already got that: "The server encountered an internal error or misconfiguration and was unable to complete your request."

However just to be sure I checked again and got the same message. Removing the erroneous text and refreshing the page removes the error.

mod_rewrite is among the loaded modules according to phpinfo()

Echoing $_SERVER[REQUEST_URI] from the page I'm redirecting to gives:

/Users/dunmail/Sites/dunmail/test/
 
I'd already got that: "The server encountered an internal error or misconfiguration and was unable to complete your request."

However just to be sure I checked again and got the same message. Removing the erroneous text and refreshing the page removes the error.

mod_rewrite is among the loaded modules according to phpinfo()

Echoing $_SERVER[REQUEST_URI] from the page I'm redirecting to gives:

/Users/dunmail/Sites/dunmail/test/

Ok so your .htaccess file is being used. Did you try my rule?

What are you trying to achieve? Because the !-d looks suspicious given your input criteria.

Are you trying to redirect or rewrite the incoming request?
 
Yes, I tried "testing 1234" and got the server error message as indicated in my previous post.

What I'm trying to do is convert a URI like "folder/test/input" in to "folder/index.php/test/input" where index.php follows the front controller pattern and in this case would route the request to the testcontroller and run the input action. I hope that makes sense.
 
I haven't done enough with custom rewriting, so this could be way off on this, but this is what I would try.

RewriteRule ^(.*)dunmail/app(.*)$ $1Sites/dunmail/index$2 [R]

PS: I would also use [R] while testing the rule, then change it back to the options you have when you know the rule is correct.
 
I *think* I've sorted it! It looks like I needed a "RewriteBase" rule as well:

PHP:
RewriteBase /~dunmail/site_folder/sub_folder

Thanks for everyone's input.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.