Setting RewriteBase automatically as the current directory?

Does anyone know if this is possible? I cant seem to find it anywhere. I have a rewrite base as

RewriteBase /webapps/funding

but if I have the my application in another folder I have to manually change my .htaccess to point to the current directory. Can it be set to ‘know’ which directory it’s in automatically?

Each folder can have it’s own htaccess file, or, I believe, you can have rewrite rules for each folder in the top level htaccess file.

Maybe posting the rules you are going to use it could help us to understand.

:slight_smile:

aaron,

WHY do you think Apache wouldn’t know what directory it’s in? Apache knows it’s in every directory in the path to the file requested. My feeble understanding of the RewriteBase is that it’s merely a shorthand to eliminate adding that directory to the RewriteRule’s redirect. As such, it can probably be overruled by a path starting with / - certainly by a redirect using an absolute path/filename (http://www.example.com/path-to-file/filename).

My question back to you is why you feel compelled to use RewriteBase (which might be explained when you reply to pippo’s request for information).

Regards,

DK

I’m using mod_rewrite to make clean URLs. Here is the .htaccess that set’s this up for me:


AcceptPathInfo On

RewriteEngine On
RewriteBase /~wiebergac/funding

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

The rewrite base here points to my testing folder for my project. If I release the project to the public use folder (in /webapps/funding) I have to change the RewriteBase so it doesnt point back to my test folder. Now I have Subversion set to ignore the .htaccess file so that when I update the public version it doesnt have to be changed, but I would still like to know if it’s possible to make the RewriteBase change no matter where I put it. I’m sure Apache knows where the file is I just dont know how to get to that information. Is there an environment variable that contains this? Or a way to strip the information from the request_uri? Thanks!

aaron,

pippo would know if there is some crafty way to do that. My put on it is to use

AcceptPathInfo On

RewriteEngine On

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

… IN the /~wiebergac/funding directory and merely transfer the entire directory when you go online. Why look for a difficult solution to a simple problem?

Okay, I’m just dense and don’t understand the problem. Yes, I have test vs production issues and use a RewriteCond to determine the host and work off that. That said, using a test directory on a production server should be as simple as what I suggested above.

Regards,

DK

From what I can tell the RewriteBase is requried for me. If it’s left out an request with a URI of

https://mysite.edu/~wiebergac/funding/Project/List

Apache will translate into

https://mysite.edu/home/wiebergac/www/funding/index.php/Project/List

unless the proper RewriteBase is given.

Maybe I’m overlooking something simple, I’m not sure. Thanks for all the help so far!