#php #codeigniter #codeigniter-4
#php #codeigniter #codeigniter-4
Вопрос:
Перенаправление маршрута на родительский домен, когда я помещаю / в конце URL
Например: Мой базовый URL-адрес: http://localhost/pep_digital/
.
Мой URL-адрес http://localhost/pep_digital/dashboard
Когда я ставлю косую черту /
в конце, как http://localhost/pep_digital/dashboard/
Он перенаправляет меня на http://localhost
После посещения этой ссылки http://localhost/pep_digital/dashboard/test/
Он перенаправляет меня на http://localhost/dashboard/test
И https://localhost/pep_digital/dashboard/test/dashboard/test/
Он перенаправляет меня на https://localhost/dashboard/test/dashboard/test
Это удаление 1-го сегмента из URL.
И следующие маршруты, которые я пробовал для всех, одинаковы.
$routes->group('dashboard', function ($routes) {
// Other routes
});
или $routes->match(['get'],'dashboard', 'Dashboard::index');
или
$routes->get('dashboard', 'Dashboard::index');
Мой .htaccess
# Protect .env
<Files .env>
Order Allow,Deny
Deny from all
</Files>
# 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
RewriteCond %{REQUEST_URI} (. )/$
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 ^([sS]*)$ index.php/$1 [L,NC,QSA]
# 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
Обновить
Ну, я обновил свою .htaccess
до последней обновленной ветки, https://github.com/codeigniter4/CodeIgniter4/blob/develop/public/.htaccess
А затем очистите мои файлы cookie и кеш и повторите попытку, и моя проблема была исправлена.
Очистка кэша происходит потому, что перенаправление было установлено на R=301
.
Комментарии:
1. Какую версию CI4 вы используете? Это была / есть известная проблема: github.com/codeigniter4/CodeIgniter4/issues/2445
2. Да, я использую CI4, и спасибо, что это мне тоже помогло.
3. Существуют версии CI4, используйте следующую команду: composer show «codeigniter4 / framework», чтобы узнать точную версию CI4.