这是我正在做的事情:
- 域名是thinkingmonkey.me
- 域名具有127.0.0.1作为IP地址
- mod_alias已安装。
我有一个名为directories.conf的conf文件。 其中我有所有有关目录的configuration。 directories.conf包含在httpd.conf
我的directories.conf有
Alias /runs /xhprof/xhprof_html <Directory /mysite/xhprof/xhprof_html> Order allow,deny Allow from all AllowOverride All </Directory>
在/mysite/xhprof/xhprof_html/.htaccess 。 我有以下几点:
RewriteEngine on RewriteBase /runs RewriteRule .* index.php
我所要做的就是将/mysite/xhprof/xhprof_html/下的任何请求指向index.php 。
当我请求不带结尾斜线的 thinkingmonkey.me/runs ,我404 not found 。
所以,我推断RewriteBase不起作用。
我究竟做错了什么?
这里有一些东西在玩。 首先, Alias指令希望它的右边是服务器上绝对的物理path:你想要的
Alias /runs /mysite/xhprof/xhprof_html <Directory /mysite/xhprof/xhprof_html> Order allow,deny Allow from all AllowOverride All </Directory>
其次,RewriteRule RewriteRule .* index.php不仅可以匹配http://.../runs ,还可以匹配任何以http://.../runs/开头的URL,例如http://.../runs/css/... 有几种方法来解决这个问题。
选项1:你可以有一个RewriteRule只redirect运行的根目录index.php:
RewriteRule ^$ index.php RewriteRule ^/$ index.php
选项2:你可以让你的mod_rewriteconfiguration特殊的东西,作为文件存在,并将其他所有东西redirect到index.php
# Require the path the request translates to is an existing file RewriteCond %{REQUEST_FILENAME} -f # Don't rewrite it, but do stop mod_rewrite processing RewriteRule .* - [L] # Now, redirect anything into index.php RewriteRule .* index.php
选项3:你可以特定的URL,并redirect到index.php
RewriteCond $1 !^css/ RewriteCond $1 !^js/ RewriteRule .* index.php
选项4:如果你想要任何URL映射到一个目录显示一个index.php文件(如index.html ),有一个非常简单的方法,这可能是你想要的。 您可以将以下内容放入.htaccess或位于directories.conf .htaccess的<Directory>块中:
DirectoryIndex index.php index.html
脚注:上面的RewriteRules基本上抛弃了所有的URL的索引,最终映射到index.php 。 这包括查询string,所以/runs/?foo=bar与/runs/相同。 如果这不是你想要的,你需要一个像这样的规则
RewriteRule ^(.*)$ index.php/$1 [QSA]
同时保留path-info( $1部分)和query-string(“QSA”=“query-string append”)。
我写了太多了吗? 🙂