Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 htaccess能否覆盖CodeIgniter';s routes.php_.htaccess_Codeigniter_Routing_Url Routing_Url Masking - Fatal编程技术网

.htaccess htaccess能否覆盖CodeIgniter';s routes.php

.htaccess htaccess能否覆盖CodeIgniter';s routes.php,.htaccess,codeigniter,routing,url-routing,url-masking,.htaccess,Codeigniter,Routing,Url Routing,Url Masking,我想知道是否有可能在Codeigniter 3中用htaccess覆盖routes.php规则 例如,为了将动态子域指向相同的控制器并将子域作为参数传递,routes.php无法做到这一点,而在htaccess中则非常简单 另一个例子是用URL段屏蔽查询字符串。php不允许使用查询字符串,但htaccess同样适用于此 因此,作为一个一般性问题,是否可以在CodeIgniter中对所有路由使用htaccess而不是使用routes.php?我认为您可以在CodeIgniter中对静态路由使用ht

我想知道是否有可能在Codeigniter 3中用htaccess覆盖routes.php规则

例如,为了将动态子域指向相同的控制器并将子域作为参数传递,routes.php无法做到这一点,而在htaccess中则非常简单

另一个例子是用URL段屏蔽查询字符串。php不允许使用查询字符串,但htaccess同样适用于此


因此,作为一个一般性问题,是否可以在CodeIgniter中对所有路由使用htaccess而不是使用routes.php?

我认为您可以在CodeIgniter中对静态路由使用htaccess。但对于动态路由应用程序库,如
您必须使用routes.php。

我认为您可以在codeigniter中使用htaccess进行静态路由。但对于动态路由应用程序库,如
您必须使用routes.php。

Codeigniter routes配置用于路由模块/控制器/方法/变量模式

我认为,域/子域从这个配置中退出,但是您可以使用基于$\服务器变量的dinamic base\ U url,然后从特定控制器获取字符串(子域)

从我的配置,在CI 2.x上

$config['base_url'] = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
$config['base_url'] .= isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' && $_SERVER['SERVER_PORT'] != '443' ? ( ':'.$_SERVER['SERVER_PORT'] ) : '';
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
然后像这样做

$server = $_SERVER['HTTP_HOST'];
$domain = preg_replace('#^www\.(.+\.)#i', '$1', $server);
$domain = $this->extract_domain($domain);
$subdomain = $this->extract_subdomains($server);

function extract_domain($domain)
{
    if(preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", $domain, $matches))
    {
        return $matches['domain'];
    } else {
        return $domain;
    }
}

function extract_subdomains($domain)
{
    $subdomains = $domain;
    $domain = $this->extract_domain($subdomains);

    $subdomains = rtrim(strstr($subdomains, $domain, true), '.');

    return $subdomains;
}
$server=$\u服务器['HTTP\u主机];
$domain=preg\u replace('\^www.++.\i','$1',$server);
$domain=$this->extract\u domain($domain);
$subdomain=$this->extract_子域($server);
函数提取\u域($domain)
{
if(preg_match(“/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i,$domain,$matches))
{
返回$matches['domain'];
}否则{
返回$domain;
}
}
函数提取_子域($domain)
{
$subdomains=$domain;
$domain=$this->extract\u domain($subdomains);
$subdomains=rtrim(strstrstr($subdomains,$domain,true),');
返回$subdomains;
}

Codeigniter路由配置用于路由模块/控制器/方法/变量模式

我认为,域/子域从这个配置中退出,但是您可以使用基于$\服务器变量的dinamic base\ U url,然后从特定控制器获取字符串(子域)

从我的配置,在CI 2.x上

$config['base_url'] = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
$config['base_url'] .= isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' && $_SERVER['SERVER_PORT'] != '443' ? ( ':'.$_SERVER['SERVER_PORT'] ) : '';
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
然后像这样做

$server = $_SERVER['HTTP_HOST'];
$domain = preg_replace('#^www\.(.+\.)#i', '$1', $server);
$domain = $this->extract_domain($domain);
$subdomain = $this->extract_subdomains($server);

function extract_domain($domain)
{
    if(preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", $domain, $matches))
    {
        return $matches['domain'];
    } else {
        return $domain;
    }
}

function extract_subdomains($domain)
{
    $subdomains = $domain;
    $domain = $this->extract_domain($subdomains);

    $subdomains = rtrim(strstr($subdomains, $domain, true), '.');

    return $subdomains;
}
$server=$\u服务器['HTTP\u主机];
$domain=preg\u replace('\^www.++.\i','$1',$server);
$domain=$this->extract\u domain($domain);
$subdomain=$this->extract_子域($server);
函数提取\u域($domain)
{
if(preg_match(“/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i,$domain,$matches))
{
返回$matches['domain'];
}否则{
返回$domain;
}
}
函数提取_子域($domain)
{
$subdomains=$domain;
$domain=$this->extract\u domain($subdomains);
$subdomains=rtrim(strstrstr($subdomains,$domain,true),');
返回$subdomains;
}