php 带有符号链接和索引文件的 .htaccess 配置无法按预期工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5412955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.htaccess config with symbolic links and index files not working as expected
提问by poolnoodl
Like a lot of web developers, I like to use .htaccess to direct all traffic to a domain through a single point of entry when the request isn't for a file that exists in the publicly served directory.
像许多 Web 开发人员一样,当请求不是针对公共服务目录中存在的文件时,我喜欢使用 .htaccess 通过单个入口点将所有流量定向到域。
So something like this:
所以像这样:
RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php [L]
This means if the request isn't for a css file or an image, my index.php gets the request and I can choose what to do (serve up some content or perhaps a 404)
这意味着如果请求不是针对 css 文件或图像,我的 index.php 会收到请求,我可以选择要做什么(提供一些内容或 404)
Works great, but I've stumbled upon an issue it can't seem to help me solve.
效果很好,但我偶然发现了一个似乎无法帮助我解决的问题。
My document root looks like this:
我的文档根目录如下所示:
asymboliclink -> /somewhere/else
css
.htaccess
img
includes
index.php
Yet, Apache doesn't see the symbolic link to a directory as a directory. It passes the request on to my index.php in the root. I want to serve the link as if it were a folder as it is a link to a folder with it's own index.php. I can access http://example.com/asymboliclink/index.phpby typing it in the address bar of a browser, but I want to be able to access it through http://example.com/asymboliclink
然而,Apache 不会将指向目录的符号链接视为目录。它将请求传递给我的根目录中的 index.php。我想提供该链接,就好像它是一个文件夹一样,因为它是一个指向具有自己的 index.php 的文件夹的链接。我可以通过在浏览器的地址栏中输入http://example.com/asymboliclink/index.php来访问它,但我希望能够通过http://example.com/asymboliclink访问它
What do I need to add to my .htaccess file to make this happen?
我需要在我的 .htaccess 文件中添加什么才能实现这一点?
回答by Jason
Use the -l
switch to test for a symbolic link
使用-l
开关测试符号链接
RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+) index.php [L]
Documentation
文档
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html- ctrl+f for "Treats the TestString as a pathname and tests whether or not it exists, and is a symbolic link."
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html- ctrl+f 表示“将 TestString 视为路径名并测试它是否存在,并且是一个符号链接。”
回答by Michael McTiernan
The -l
flag references symbolic links
该-l
标志引用符号链接
RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+) index.php [L]