【问题标题】:codeigniter public directory in urlurl中的codeigniter公共目录
【发布时间】:2013-03-28 07:27:45
【问题描述】:

例如:

- index.php
- /system
- /application
   - /controller
      - test.php (class:test ; function index() ; echo "hi")
- /public
   - style.css

我将浏览器指向http://mysite.com/,它会显示“hi”

如果我想要style.css,我必须指向http://mysite.com/public/style.css

但我想指出http://mysite.com/style.css也可以显示style.css

我尝试将 index.php 移动到公共添加前缀 ../ 之前的系统和应用程序

另外我在根目录设置了一个htaccess,然后我可以成功指向http://mysite.com/style.css for style.css

但还有一个问题,我不能再指向我的测试控制器,它显示错误 404

如何保留两个网址?

更新:

根目录中的htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^public/.+$ - [L]

RewriteCond %{DOCUMENT_ROOT}/public/$0 -f
RewriteRule ^.+$ /public/$0 [L]

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

当我访问http://mysite.com/style.css时可以显示style.css

但控制器测试不起作用,我访问 http://mysite.com/test/test/index 显示 404 不是“hi”

【问题讨论】:

  • 将它放在 /public/ 中并通过 /public/style.css 调用它是有意义的;那有什么问题?另外,请发布您的 .htaccess。
  • 您在 htaccess 中的重写规则似乎有问题,请发布您的 htaccess 以获得更多帮助

标签: php .htaccess codeigniter directory rewrite


【解决方案1】:

如果请求的文件来自公共目录,您可以使用RewriteCond 进行测试

# prevent requests for the public directory from being rewritten
RewriteRule ^public/.+$ - [L]

RewriteCond %{DOCUMENT_ROOT}/public/$0 -f
RewriteRule ^.+$ /public/$0 [L]

您必须在 Codeigniter 规则之前插入此规则,否则文件可能会被重写为 /index.php/...

更新

首先,您必须省略RewriteCond !-f/!-d

test/index 的 URL 必须是 http://mysite.com/test/indexhttp://mysite.com/test

【讨论】:

  • 这可以显示css文件,但是我的控制器是404 nt,我更新了问题
  • @jkjk 在您的问题中显示完整的 .htaccess。
猜你喜欢
  • 2011-10-10
  • 1970-01-01
  • 2010-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多