【问题标题】:Moving working CodeIgniter website to subfolder将工作的 CodeIgniter 网站移动到子文件夹
【发布时间】:2023-03-19 08:33:01
【问题描述】:

我有一个完美运行的网站作为我的虚拟主机 (/public_html) 的根目录,但我最近购买了一个新域并将它也停在那里,所以我需要一个子目录 (/public_html/newdomaindir)。

现在我需要将我的整个网站移动到一个子文件夹 (/public_html/website) 并且我很难调整 .htaccess 文件。

这是我作为 root 时的旧工作 .htaccess 文件:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.org$
RewriteRule ^/?$ "http\:\/\/www\.website\.org\/" [R=301,L]

#SetEnvIfNoCase Host ^www\.website\.org$ require_auth=true

RewriteCond $1 !^(index\.php|images|css|robots\.txt|js|icons|files|fonts|extplorer)
RewriteRule ^(.+)$ /index.php?/$1[L,QSA]

现在 webhost 支持建议我将这个 .htaccess 文件作为 root 来重定向流量。

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} website.org$
RewriteCond %{REQUEST_URI} !website/
RewriteRule ^(.*)$ website/$1

但是,嗯……它没有按预期工作。我的网站坏了。

我是否应该使用不同的方法,也许请支持人员更改我网站的 document_root?我应该更改子文件夹 .htaccess 文件中的任何内容吗?

非常感谢任何帮助。谢谢。

【问题讨论】:

  • 您是否尝试过在 CI 配置文件中更改 base url
  • 这不应该改变。还是$config['base_url'] = 'http://www.website.org/';
  • 请尝试使用原始 .htaccess 将 $config['base_url'] = 'http://www.website.org/'; 更改为 $config['base_url'] = 'http://www.website.org/website';

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:

不是我最强的技能,但我会尝试将您以前的.htaccess修改为以下形式:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.org$
RewriteRule ^/?$ "http\:\/\/www\.website\.org\/" [R=301,L]

# not sure what about this
#RewriteCond $1 !^website\/(index\.php|images|css|robots\.txt|js|icons|files|fonts|extplorer)
RewriteRule ^$ website/ [L]
RewriteRule ^(.+)$ website/index.php?/$1[L,QSA]

如果这不起作用,也许你会在this SO answer中找到一些线索。

【讨论】:

  • 让它与 RewriteBase 一起工作,而不是更改 RewriteRules
猜你喜欢
  • 1970-01-01
  • 2019-11-19
  • 2012-08-30
  • 2014-10-29
  • 2015-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-12
相关资源
最近更新 更多