Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

The following rule in my .htaccess works just fine for routing calls to index.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

However, this does not work when running on a temporary URL like http://example.com/~test/.

In such a case, the .htaccess file needs to read:

RewriteEngine On
RewriteBase /~test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

Note the extra RewriteBase.

Question: is it possible to write a rule in .htaccess to "detect" whether to apply that RewriteBase?

The reason is the .htaccess if version controlled, and I'd like for it to work on multiple installations.

share|improve this question
    
I've spent so long screwing around with this, and have found the same problem. Why the hell cant RewriteBase have the same value as Alias? It's crazy... –  nbolton Jun 8 '12 at 21:02
    
Yes, it seems like a pain that's just "one of those things". –  eoinoc Jun 12 '12 at 22:10
add comment

1 Answer

up vote 1 down vote accepted

As far as I know, there's no reliable way to detect what the RewriteBase should be. If there were, there would be no need for the kluge that RewriteBase is, as mod_rewrite could just detect the correct base automatically.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.