Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 子文件夹处的Codeigniter和内部重定向的htaccess_.htaccess_Mod Rewrite_Codeigniter 2_Subdirectory - Fatal编程技术网

.htaccess 子文件夹处的Codeigniter和内部重定向的htaccess

.htaccess 子文件夹处的Codeigniter和内部重定向的htaccess,.htaccess,mod-rewrite,codeigniter-2,subdirectory,.htaccess,Mod Rewrite,Codeigniter 2,Subdirectory,我有一个后端带有定制引擎的项目,我正试图用我的CodeIgniter钩住/somewhere/上的每个请求。因此,我将我的CI放到/www/somewhere/,用新的RewriteBase配置了我的CodeIgniter的.htaccess,因此它现在看起来像: AddDefaultCharset UTF-8 Options All -Indexes <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /somewhere/

我有一个后端带有定制引擎的项目,我正试图用我的CodeIgniter钩住
/somewhere/
上的每个请求。因此,我将我的CI放到
/www/somewhere/
,用新的RewriteBase配置了我的CodeIgniter的.htaccess,因此它现在看起来像:

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>
一切正常。但是但是我需要在URL中打开我的编译文件而不使用
/compiled/

作品:
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/
(事实上,我在这里的某个地方有这个
的管理面板)

所以。。我想直接从我的
/compiled/
打开文件,但我还需要保存我的CI。我应该在.htaccess中添加什么?

已测试并正常工作

其思想是验证
请求URI
而不是
/system/
/application/
并查看它是否存在于
/compiled/
文件夹中

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中避开了
/where/
。也许你也必须在我的代码中避免它(取决于服务器配置)

谢谢!很好,而且我从你的回答中学到了一些东西。很高兴检查您的答案是否正确并给予奖励!再次感谢!我如何拒绝直接访问我的
/compiled/
www.domain.com/somewhere/compiled/test.html
,但授予访问
www.domain.com/somewhere/test.html
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]