子文件夹和htaccess中的Codeigniter用于内部重定向
我在后端有一个带有自定义引擎的项目,我试图用我的CodeIgniter挂钩/somewhere/
上的每个请求.因此,我将CI放入/www/somewhere/
,并使用新的RewriteBase配置了CodeIgniter的.htaccess,现在看起来像这样:
I have a project with custom engine at backend, I'm trying to hook every request at /somewhere/
with my CodeIgniter. So I put my CI to /www/somewhere/
, configured my CodeIgniter's .htaccess with new RewriteBase, so it now looks like:
AddDefaultCharset UTF-8
Options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /somewhere/
DirectoryIndex index.html index.php
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
我的CI为该项目创建了静态html并将其存储在/compiled/
中,因此我具有此结构
My CI creates static html for this project and stores it at /compiled/
, so I have this structure
/www/
/custom-engine/
/img/
/js/
/somewhere/ <--- My CI's root
/application/
/system/
/compiled/ <--- My storage for HTML
my-file.html
/my-compiled-folder/
/one-more/
/sub-compiled/
index.html
一切正常.但.但是我需要打开URL中没有/compiled/
的编译文件.
And everything works fine. But. But I need to open my compiled files without /compiled/
in URL.
Works:http://domain.com/somewhere/compiled/one-more/sub-compiled/
需要:http://domain.com/somewhere/one-more/sub-compiled/
我不需要重定向到我的已编译文件夹/文件,只需打开它即可.因此,我需要在.htaccess中添加一些内容.我也想继续访问我的CI.例如,我有控制器helloworld
,现在可以从http://domain.com/somewhere/helloworld/
进行访问(实际上,这里有此somewhere
的管理面板).
I needn't redirect to my compiled folder/file, just open it. So I need add something to my .htaccess. Also I want keep access to my CI. For example I have controller helloworld
and now it accessible from http://domain.com/somewhere/helloworld/
(in fact I have administration panel for this somewhere
here).
所以..我想直接从/compiled/
打开文件,但是我还需要保存CI.我应该在.htaccess文件中添加些什么?
So.. I want to open files directly from my /compiled/
, but also I need to save my CI. What should I add to my .htaccess?
经过测试,可以正常工作.
Tested and working.
这个想法是验证除/system/
或/application/
之外的REQUEST_URI
,并查看它是否存在于/compiled/
文件夹中.
The idea is to verify REQUEST_URI
other than /system/
or /application/
and see if it exists into /compiled/
folder.
RewriteEngine On
RewriteBase /somewhere/
RewriteCond %{REQUEST_URI} ^/somewhere/(system|application)/ [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^/somewhere/(.+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/somewhere/compiled/%1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/somewhere/compiled/%1 -f
RewriteRule . compiled/%1 [L]
您似乎避免在htaccess中使用/somewhere/
.也许您也必须在我的代码中避免使用它(取决于服务器配置)
You seem to avoid /somewhere/
in your htaccess. Maybe you will have to avoid it in my code also (depends on server configuration)