我正在尝试让"trac“目录和它的所有子目录都可以通过url http://www.domain.com/trac/访问
我正在使用codeginiter框架,我的目录结构看起来像这样
.htaccess
index.php
system
trac我可以很好地访问上面的url,但问题是trac子目录中包含的脚本和其他文件(即trac/chrome/common/css/trac.css )是不可访问的。这是我的.htaccess代码。请帮帮忙。
RewriteEngine On
RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^trac/
RewriteRule ^trac/(.*) /trac/$1发布于 2009-12-19 23:19:36
你甚至不需要在你的.htaccess中提到/trac/。这正是我要说的
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d您正在设置两个“重写条件”。第一个是说,“只要请求不是文件。”第二个是“或者只要请求不是一个目录”。
然后
RewriteRule ^(.*)$ index.php?/$1 [L]将其他所有内容发送到index.php,由CI接管。仅供记录,我在每个项目中使用的完整.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]如果您对系统行感到困惑,那么它的存在只是为了让对/ RewriteCond %{REQUEST_URL} ^system.* /文件夹的任何浏览器请求总是被路由到index.php,并因此被忽略。
发布于 2009-12-18 22:03:40
重写规则按顺序执行...所以试试这个吧
RewriteCond %{REQUEST_URI} !^/trac/
RewriteCond $1 !(index\.php/)
RewriteRule ^(.*)$ index.php?/$1 [L]解释:
if the uri DOES NOT start with trac
if the uri IS NOT index.php
rewrite url as index.php?/{rest of the url}发布于 2009-12-18 08:00:56
如果您删除最后两行,它应该可以工作。
RewriteCond %{REQUEST_FILENAME} !-f检查以确保您不是在请求文件。如果是,则此条件将失败,并且永远不会执行规则RewriteRule ^(.*)$ index.php?/$1 [L]。
https://stackoverflow.com/questions/1923186
复制相似问题