gpt4 book ai didi

.htaccess - 在子目录中安装 Codeigniter 4 并保留域通用 URL 结构

转载 作者:行者123 更新时间:2023-12-02 00:03:44 24 4
gpt4 key购买 nike

现状:

我已经在 http://example.com 上安装了 Wordpress,并且这个站点是多语言的,因此您可以在 http://example.com/上访问英文网页en/something-here/,您可以在 http://example.com/es/algo-aqui/ 访问此网页的西类牙语版本。

我正在尝试做的事情:

我想在 http://example.com/software/ 中安装 Codeigniter 4 但我想保留一般的网站 URL 结构,所以我需要能够通过以下方式访问 CI4 软件URL http://example.com/en/software/http://example.com/es/software/。始终阅读本段开头提到的相同 CI4 安装。

我已经尝试过的:

我在 http://example.com/software/ 部署了 CI4 文件,并修改了 Wordpress 站点和 Code Igniter 的 .htaccess 文件。

这是我在根目录下的 WP .htaccess 文件:

# Disable directory browsing
Options All -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[a-z]{2}/software(.*)$ /software/index.php$2 [L]
</IfModule>

# BEGIN WordPress
# Las directivas (líneas) entre `BEGIN WordPress` y `END WordPress` se generan dinámicamente
# , y solo se deberían modificar mediante filtros de WordPress.
# Cualquier cambio en las directivas que hay entre esos marcadores se sobreescribirán.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

这是我在“软件”目录中的 .htaccess 文件:

# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
RewriteBase /

# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /software/index.php/$1

# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
ServerSignature Off
# Disable server signature end

我得到的错误:

我可以同时访问站点和软件。该站点运行良好,但是当我尝试访问 http://example.com/en/software/ 时,我在访问 Codeigniter 时收到 404 错误。错误消息显示:“找不到 Controller 或其方法:App\Controllers\En::software”。

这就好像 CI 试图找到 Controller En(不存在)和方法 software

我们将不胜感激。

最佳答案

经过2天的不懈努力,我已经解决了这个问题。这是我实际遵循的步骤-

首先以 root 身份执行以下命令备份 Codeigniter4 应用程序:

tar --exclude=".git" -czvf zipped_file_name.tar codeigniter4_project_folder/

在 Shared Hosing 上传 public_html 目录中的 codeigniter4_project_folder 并更改以下内容:

  1. 更改 app/Config/App.php 中的基本 url 或 codeigniter 应用程序根文件夹中的 .env 文件(这里的 ci4 是稍后将在 cpanel 中配置的子域)

    app.baseURL = 'http://ci4.yourdomain.com/'

  2. 更改根文件夹中 app/Config/Database.php 或 .env 文件中的数据库配置
    database.default.hostname = localhost
    database.default.database = your_db_name
    database.default.username = your_db_user
    database.default.password = your_db_password
    database.default.DBDriver = MySQLi

  3. 更改公用文件夹中的 .htaccess 文件
    RewriteBase/codeigniter4_project_folder/

  4. 在 Cpanel ci4.yourdomain.com 添加子域,路径如下:public_html/codeigniter4_project_folder/public

此处公用文件夹将是路径中的最后一个。这是非常重要的。希望这可以帮助其他人解决这个问题。

关于.htaccess - 在子目录中安装 Codeigniter 4 并保留域通用 URL 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61314038/

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