gpt4 book ai didi

php - 如何调整我的 .htaccess 文件以允许子文件夹中的全功能网站

转载 作者:太空宇宙 更新时间:2023-11-03 14:45:31 25 4
gpt4 key购买 nike

我有一个运行良好的网站。我想在子文件夹而不是子域中创建另一个。这样做的主要考虑是我需要为这两个站点安装 tls cert。由于父网站使用 tls 证书,我希望它能覆盖 child (我现在买不起另一个)。问题是我在两个网站中都有 .htaccess 文件,如下所示:

Options -MultiViews
RewriteEngine On

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

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

父网站仍在运行,但我无法访问“子”网站。

编辑:

虽然我不认为路由是问题,但我应某人的要求将我的机制发布在这里

class App{

protected $controller = 'welcome';
protected $method = 'index';
protected $params;

public function __construct(){
$url = $this->parseURL();

if( isset( $url[0] ) && file_exists( 'app/controllers/' . strtolower( $url[0] ) . '.php' ) )
{
$this->controller = $url[0];
unset( $url[0]);
}

require_once 'app/controllers/' . strtolower( $this->controller ). '.php';

$this->controller = new $this->controller;

if( isset( $url[1] ) )
{
if( method_exists( $this->controller, $url[1] ) )
{
$this->method = $url[1];
unset( $url[1] );
}
}

$this->params = $url ? array_values( $url ) : [];

call_user_func_array( [ $this->controller, $this->method ], $this->params );
}

protected function parseURL(){

if( isset( $_GET['url'] ) ){

//return $url = explode( '/', filter_var( rtrim( $_GET['url'], '/') ), FILTER_SANITIZE_URL );
return $url = explode( '/', filter_var( rtrim( $_GET['url'], '/' ), FILTER_SANITIZE_URL ) );
}
}
}

这是 Controller 基类:

abstract class Controller{

protected $response = array();

protected $dbInstance = false;

protected function model( $model ){
require_once 'app/models/' . strtolower( $model ) . '.php';
return new $model();
}

protected function view( $view, $data = [] ){

require_once 'app/views/' . strtolower( $view ) . '.php';
}
}

最佳答案

因此,您需要从 .htaccess 中排除一个子文件夹,因为您有一个子域,要实现此目的,只需排除 directory1directory2(作为前任):

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^/?(directory1|directory2)/ !-d

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

P.S:未测试但应该可以工作

关于php - 如何调整我的 .htaccess 文件以允许子文件夹中的全功能网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39334426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com