在子目录中安装Codeigniter 4并保留域常规URL结构 [英] Installing Codeigniter 4 in a subdirectory and keep the domain general URL structure
问题描述
当前情况:
我已经在http://example.com
安装了Wordpress,并且此站点是多语言的,因此您可以在http://example.com/en/something-here/
访问英文网页,在http://example.com/es/algo-aqui/
访问此网页的西班牙语版本。
我正在尝试执行的操作:
我想在http://example.com/software/
中安装Codeigniter 4,但我想保留一般的网站URL结构,因此我需要能够通过URLhttp://example.com/en/software/
和http://example.com/es/software/
访问CI4软件。始终阅读本段开头提到的同一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
这是我在"SOFTWARE"目录下的.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错误。错误消息显示:"找不到控制器或其方法:AppControllersEn::Software"。
这就好像CI正在尝试查找控制器En
(该控制器不存在)和方法software
。
如有任何帮助,我们将不胜感激。
推荐答案
经过2天的不懈尝试,问题终于解决了。以下是我实际遵循的步骤-
首先以root身份发出以下命令备份Codeigniter4应用程序:
tar --exclude=".git" -czvf zipped_file_name.tar codeigniter4_project_folder/
上传共享软管的public_html目录中的codeigniter4_project_older,并更改以下内容:
更改codeigniter应用程序根文件夹中app/Config/App.php或.env文件中的基本url(其中ci4是稍后将在cPanel中配置的子域)
app.baseURL = 'http://ci4.yourdomain.com/'
更改根文件夹中的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
更改公用文件夹中的.htaccess文件
RewriteBase /codeigniter4_project_folder/
在Cpanel ci4.youdomain.com中添加子域,路径如下:
public_html/codeigniter4_project_folder/public
这篇关于在子目录中安装Codeigniter 4并保留域常规URL结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!