Using relative urls with mod_rewrite

Environment: Apache 2 ships with Mac OS X Leopard; no big changes to the default httpd.conf file.

I am setting up some rewrites through my .htaccess, but I cannot seem to target the paths relative to the current directory.

# URL: http://localhost/~davis/rewrite/.htaccess
# File: /Users/davis/Sites/rewrite/.htaccess

RewriteRule go.php target.php

# Not working

      

I expect the rule to redirect users to http://localhost/~davis/rewrite/target.php

. It resolves the correct physical path, but gives 404 words that the path /Users/davis/Sites/rewrite/target.php

does not exist.

Everything works well if I give the full URL.

# URL: http://localhost/~davis/rewrite/.htaccess
# File: /Users/davis/Sites/rewrite/.htaccess

RewriteRule go.php /~davis/rewrite/target.php

# Works

      

Am I missing something? Anything to set up in httpd.conf?

Thank!

Edit: Relative urls work on my real Linux server. It's in my local Mac box that I'm having problems.

+2


source to share


3 answers


Got it finally!

It starts working if I install DocumentRoot

in the ~ / Sites directory or create a VirtualHost

path for that. Apparently, in the user's directory settings, Apache was unable to map the physical path to the alias ~username

.



Thanks everyone for your input!

+1


source


Try setting up your base url:



RewriteBase /~davis/rewrite/

      

+1


source


You can try RewriteBase, but other than that I don't think you can do anything.

RewriteBase /~davis/rewrite/

      

0


source







All Articles