我使用.htaccess将来自backoffice.3incheslong.com的所有请求重写到/ application / controllers / backoffice /中的子文件夹控制器,使用的.htaccess是:
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^3incheslong\.com
RewriteRule (.*) http://www.3incheslong.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^backoffice\.3incheslong\.com
RewriteCond %{REQUEST_URI} !^/backoffice
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /backoffice/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
htaccess似乎有效,但backoffice.3incheslong.com正在使用/controllers/index.php而不是/controllers/backoffice/index.php
这是我在www.3incheslong.com上使用var_export()$ _SERVER的结果:
array (
'UNIQUE_ID' => 'ThbVpsCoAAwAAAKSGoYAAAAM',
'HTTP_HOST' => 'www.3incheslong.com',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_LANGUAGE' => 'sv-se,sv;q=0.8,en-us;q=0.5,en;q=0.3',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_CONNECTION' => 'keep-alive',
'PATH' => '/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin',
'SERVER_SIGNATURE' => '',
'SERVER_SOFTWARE' => 'Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/1.0.0d DAV/2 PHP/5.3.5',
'SERVER_NAME' => 'www.3incheslong.com',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'REMOTE_ADDR' => '127.0.0.1',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/bidpart/public_dev/',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/bidpart/public_dev/index.php',
'REMOTE_PORT' => '63771',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => '',
'REQUEST_URI' => '/',
'SCRIPT_NAME' => '/index.php',
'PHP_SELF' => '/index.php',
'REQUEST_TIME' => 1310119334,
)
这是在backoffice.3incheslong.com上使用var_export()的结果:
array (
'REDIRECT_REDIRECT_UNIQUE_ID' => 'ThbVlsCoAAwAAAKRGoMAAAAL',
'REDIRECT_REDIRECT_STATUS' => '200',
'REDIRECT_UNIQUE_ID' => 'ThbVlsCoAAwAAAKRGoMAAAAL',
'REDIRECT_STATUS' => '200',
'UNIQUE_ID' => 'ThbVlsCoAAwAAAKRGoMAAAAL',
'HTTP_HOST' => 'backoffice.3incheslong.com',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_LANGUAGE' => 'sv-se,sv;q=0.8,en-us;q=0.5,en;q=0.3',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_CACHE_CONTROL' => 'max-age=0',
'PATH' => '/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin',
'SERVER_SIGNATURE' => '',
'SERVER_SOFTWARE' => 'Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/1.0.0d DAV/2 PHP/5.3.5',
'SERVER_NAME' => 'backoffice.3incheslong.com',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'REMOTE_ADDR' => '127.0.0.1',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/bidpart/public_dev/',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/bidpart/public_dev/index.php',
'REMOTE_PORT' => '63696',
'REDIRECT_URL' => '/backoffice/',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => '',
'REQUEST_URI' => '/',
'SCRIPT_NAME' => '/index.php',
'PATH_INFO' => '/backoffice/',
'PATH_TRANSLATED' => 'redirect:/index.php/backoffice//',
'PHP_SELF' => '/index.php/backoffice/',
'REQUEST_TIME' => 1310119318,
)
重定向似乎工作(?)但不知何故,Codeigniter仍在使用我的默认控制器,而不是后台控制器。如果我访问www.3incheslong.com/index.php/backoffice或www.3incheslong.com/backoffice,我将获得后台控制器..
有什么想法吗?
答案 0 :(得分:0)
我认为第11行(?):
RewriteRule (.*) /backoffice/$1 [L]
您正在绕过codeigniter的前端控制器,您可以尝试:
RewriteRule (.*) index.php/backoffice/$1 [L]