只有默认路由在 cakephp 3.6 中工作,可能与 htaccess 有问题
Only default Routing working in cakephp 3.6, may be issue with htaccess
我正在下载 cakephp 3.6,当我尝试使用默认路由时它工作正常。但是当我在 / 之后添加一些东西时。它 git 我的 404 错误这是我的路由器代码
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
当我请求 http://localhost/cake/my_app_name/ 时它工作正常
但是当我点击 http://localhost/cake/my_app_name/pages/10 它给了我 404 错误
我的 webroot htaccess 文件代码在这里
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url= [QSA,L]
</IfModule>
app htaccess 代码在这里
# Uncomment the following to prevent the httpoxy vulnerability
# See: https://httpoxy.org/
#<IfModule mod_headers.c>
# RequestHeader unset Proxy
#</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/ [L]
</IfModule>
您需要创建一个名为 10.ctp 的文件并将其放入 src/Template/Pages。
您需要将 AllowOverride All
指令添加到 Apache 配置中的应用程序文件夹。
<Directory /var/www/your/app/dir>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
我正在下载 cakephp 3.6,当我尝试使用默认路由时它工作正常。但是当我在 / 之后添加一些东西时。它 git 我的 404 错误这是我的路由器代码
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
当我请求 http://localhost/cake/my_app_name/ 时它工作正常 但是当我点击 http://localhost/cake/my_app_name/pages/10 它给了我 404 错误
我的 webroot htaccess 文件代码在这里
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url= [QSA,L]
</IfModule>
app htaccess 代码在这里
# Uncomment the following to prevent the httpoxy vulnerability
# See: https://httpoxy.org/
#<IfModule mod_headers.c>
# RequestHeader unset Proxy
#</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/ [L]
</IfModule>
您需要创建一个名为 10.ctp 的文件并将其放入 src/Template/Pages。
您需要将 AllowOverride All
指令添加到 Apache 配置中的应用程序文件夹。
<Directory /var/www/your/app/dir>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>