开发者

RewriteRules that match inside an Apache Alias or not

I have an application that operates in a few different environments, sometimes it's at the top level in a site or sometimes it's operating inside an alias.

When it's a straight checkout to a normal docroot my .htaccess is something like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

I deployed the site in an environment that had an alias like the following:

Alias /foo /path/to/my/application/

I found I had to modify the .htaccess to the following:

RewriteEngine On
RewriteBase /foo
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l开发者_运维问答 [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /foo/index.php [NC,L]

My question is, how can I rewrite my .htaccess so that the rewriting works the same whether it's under an alias or not? Is there some way I can detect if an alias has been set, or some other way of phrasing the RewriteRules?


Since mod_rewrite takes precedence over mod_alias, you probably need to replace your aliases with rewrite rules.

This:

Alias /foo /path/to/my/application/

would become:

RewriteRule ^foo.*$ path/to/my/application$1 [L]

Then the rules in the .htaccess file that may or may not be at the root should work without you having to change them.


Solution is creating a symlink, if you have access to your document root:

ln -s /<path to application> /<document root>/foo
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜