- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在寻找一种解决方案来支持一个虚拟主机帐户上的多个域,这必须使用 htaccess 来完成。所以这个想法是,你调用 domainx 并使用 htaccess 服务器将 webroot “伪造”到与域名对应的子文件夹。我已经有了一个“解决方案”,但这并不完美。
我遇到的问题:
那么,我目前使用的 htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domein1.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/domein1.nl/.*$
RewriteRule ^(.*)$ /domein1.nl/$1 [L]
RewriteCond %{HTTP_HOST} domein2.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/domein2.nl/.*$
RewriteRule ^(.*)$ /domein2.nl/$1 [L]
</IfModule>
base_url() 的 CodeIgniter PHP 代码。 服务器变量“SCRIPT_NAME”添加了第二个域文件夹,标记为问题 1。如果正确伪造了根文件夹,则不会发生这种情况;但这真的可能吗?
if (isset($_SERVER['HTTP_HOST']))
{
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$base_url .= '://'. $_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
最后但同样重要的是,当我通过我的主机文件进行重定向时,它无法在我的本地服务器上运行:
192.168.2.9 local.domein1.nl
192.168.2.9 local.domein2.nl
Sooo.. 我该如何解决这些问题?提前致谢!
编辑:我本地服务器的问题已修复。咳咳“sudo a2enmod rewrite”成功了。
编辑 2:由于 stormdrain 开始介绍文件夹结构,我在这里澄清多个 CI 应用程序。
主要的 .htaccess 位置/webroot
/public_html/.htaccess
域 1:
/application/domain1/ (domain1 application path)
/application/system/ (shared system path)
/public_html/domain1/index.php (CI domain1 index)
域 2:
/application/domain2/ (domain2 application path)
/application/system/ (shared system path)
/public_html/domain2/index.php (CI domain2 index)
最佳答案
目前还不完全清楚您要做什么。听起来您有几个域名指向同一台服务器,您在其中没有完全控制权,因此无法设置 VirtualHosts。您还希望使用单个应用程序为域提供服务,并且不希望将子文件夹作为 URL 的一部分(例如,您不希望 http://www.domain1.nl/domain1.nl 作为 URL 的主页)。
如果是这样,这可能有效:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domein1.nl$ [NC]
RewriteRule ^(.*)$ /domein1/$1 [L]
RewriteCond %{HTTP_HOST} domein2.nl$ [NC]
RewriteRule ^(.*)$ /domein2/$1 [L]
</IfModule>
然后在 CodeIgniter 中创建路由来路由请求:
$route["/domein2/(:any)"] = "/domein2/$1";
要使重写在本地工作,您需要将域添加到 .htaccess
文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} local.domein1.nl$ [NC]
RewriteRule ^(.*)$ /domein1/$1 [L]
RewriteCond %{HTTP_HOST} local.domein2.nl$ [NC]
RewriteRule ^(.*)$ /domein2/$1 [L]
</IfModule>
那么 base_url 不需要 SCRIPT_NAME,因为它正在被重写并从 URL 中路由出来:
if (isset($_SERVER['HTTP_HOST']))
{
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$base_url .= '://'. $_SERVER['HTTP_HOST']. '/';
}
更新。
如果每个域都有一个 CI 文件夹,例如:
/var/www/domain1/index.php
/var/www/domain1/application/
/var/www/domain1/system/
等等
/var/www/domain2/index.php
/var/www/domain2/application/
/var/www/domain2/system/
等等
RewriteCond %{HTTP_HOST} domain1.nl$ [NC]
RewriteRule ^(.*)$ /domain1/$1 [L]
RewriteCond %{HTTP_HOST} domain2.nl$ [NC]
RewriteRule ^(.*)$ /domain2/$1 [L]
应该为您完成这项工作。
关于php - .htaccess 多域重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13309999/
是否可以在 .htaccess 中包含来自另一个 htaccess 文件的规则? .htaccess RewriteEngine On RewriteCond ... RewriteRule ...
我正在尝试做的事情: 在我的特定项目的服务器上,我想通过 htaccess 编写 URL 重写规则(从 URL 中删除 .php 或 .html 扩展名)。 我的网站网址: http://enacte
在我的 .htaccess 文件中我已经有一些重写条件和规则,并且它工作正常。 现在我需要将“http 到 https 重定向”添加到我的 htaccess 文件中。 这是我的旧 .htaccess
注意:我写了解决方案。不管怎样,谢谢你。 :) 我知道这似乎是重复的问题:我搜索了很多,我应用了数十条重写规则,但它们不起作用。 我需要从 重定向 www.domain.com/folder1 到 w
我有一个带有 drupal 的多站点,我创建了一个站点,该站点起初应该可以通过多种方式(子域和路径)访问,但现在我只想保留其中一个;所以我应该重定向所有其他人。现在我有: aaa.domain.com
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我将我的网站从/v1/etc... 目录移动到/v2/etc... 目录,并希望在 htaccess 中进行永久重定向。有人能帮我吗? 最佳答案 您可以使用 mod_rewrite : Rewrite
我想通过 .htaccess 保护文件夹。以下不起作用。它在浏览器中显示登录对话框,但看起来好像用户名和密码不匹配。当我将方法更改为 Basic 时,它运行良好。 AuthUserFile /home
任何人都可以解释以下行吗? RewriteRule ^(.*)$ /index.php/$1 [L] 最佳答案 重写规则的部分分解如下: 重写规则 表示此行将是重写规则,而不是重写条件或其他重写引擎指
我正在尝试从一个域中一个目录中的所有文件创建一个永久的 htaccess 重定向(301)到另一个域,如下所示: 重定向以下目录中的所有文件: http://www.primary.com/apple
我不是 .htaccess 的英雄,但我遇到了一个我认为可能是由它引起的问题。 第一个症状:对我的数据库的简单更改(如用户 IP 跟踪)每次请求都完成了多次,而站点的输出看起来还不错。 经过数小时的跟
我想做一个类似basecamp.com的东西:你公司的名字变成三级域名,http://mycompany.basecamp.com例如。我知道它(很可能)是在.htaccess文件和mod_rewri
我已阅读 this这对我的要求来说似乎太长了。 并尝试过 Redirect /index.php /index2.php但它不起作用(内部服务器错误) 我想要的是将我的一些 php 文件重定向到 in
如果使用此代码,则成功: Redirect 301 /products.php http://website.com.au/product_123.php 但是,如果执行此操作,则不是: Redire
我想重定向这个子域: http://abc.domain-name.com 到根域上使用相同名称的文件夹: http://www.domain-name.com/abc 这样,如果我尝试访问以下文件:
我已经在我的实时站点上设置了 htpasswd 身份验证,并且效果很好,但是当我在开发环境中工作时,我不想被要求输入密码。 在我的 httpd.conf 文件中,我有: SetEnv APP_ENV
之前 我安装了 SSL,一切运行良好!!这是我的根网络服务器 .htaccess 文件中的代码: Options +MultiViews RewriteEngine On RewriteCond %{
我要问一个非常简单的问题。当我运行我的页面时,我不希望我的链接显示这个: http://localhost/example/assets/gallery.php 我想要的是: http://local
我在 htaccess 中有说明,可以让所有请求都通过 index.php 文件。但它禁止访问文件夹和文件。因此,如果我尝试转到/uploads/products/thumbs/file.png 它会
我有一个这样的网址:https://example.com/coins/1&order_by=today以及几个类别,例如: https://example.com/coins/1&order_by=
我是一名优秀的程序员,十分优秀!