yii2 .htaccess 子目录路由不起作用
yii2 .htaccess subdirectory route is not working
我在根目录中的 htaccess 配置看起来像
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(assets|css|js|images|blog)
RewriteRule ^assets/(.*)$ frontend/web/assets/ [L]
RewriteRule ^css/(.*)$ frontend/web/css/ [L]
RewriteRule ^js/(.*)$ frontend/web/js/ [L]
RewriteRule ^images/(.*)$ frontend/web/images/ [L]
RewriteRule ^blog/(.*)$ frontend/web/blog/ [L]
RewriteRule ^(.*)$ frontend/web/ [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js|blog)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
在 frontend/web 看起来像
RewriteEngine on
RedirectMatch 404 /\.git
RedirectMatch 404 /composer\.
RedirectMatch 404 /.bowerrc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
图像、css、js 一切正常(例如,路径站点。com/images 工作正常)除了“/blog”页面,单击菜单按钮后,应用程序将我重定向到"site.com/frontend/web/blog" 而不是 "site.com/blog"
我正在使用 yii2 NavBar 小部件
$menuItems = [
...
['label' => 'Blog', 'url' => ['/blog/index'], 'options'=>['class'=>'font-menu']],
url 经理规则
'rules' => [
'blog/<url>/<category_id>' => 'blog/one',
'blog/<category_id>' => 'blog/category',
'blog' => 'blog/index',
不明白如何解决,请帮忙
通过这种方式找到了解决方案
在主本地配置中
'request' => [
'baseUrl' => '',
],
我在根目录中的 htaccess 配置看起来像
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(assets|css|js|images|blog)
RewriteRule ^assets/(.*)$ frontend/web/assets/ [L]
RewriteRule ^css/(.*)$ frontend/web/css/ [L]
RewriteRule ^js/(.*)$ frontend/web/js/ [L]
RewriteRule ^images/(.*)$ frontend/web/images/ [L]
RewriteRule ^blog/(.*)$ frontend/web/blog/ [L]
RewriteRule ^(.*)$ frontend/web/ [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js|blog)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
在 frontend/web 看起来像
RewriteEngine on
RedirectMatch 404 /\.git
RedirectMatch 404 /composer\.
RedirectMatch 404 /.bowerrc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
图像、css、js 一切正常(例如,路径站点。com/images 工作正常)除了“/blog”页面,单击菜单按钮后,应用程序将我重定向到"site.com/frontend/web/blog" 而不是 "site.com/blog"
我正在使用 yii2 NavBar 小部件
$menuItems = [
...
['label' => 'Blog', 'url' => ['/blog/index'], 'options'=>['class'=>'font-menu']],
url 经理规则
'rules' => [
'blog/<url>/<category_id>' => 'blog/one',
'blog/<category_id>' => 'blog/category',
'blog' => 'blog/index',
不明白如何解决,请帮忙
通过这种方式找到了解决方案
在主本地配置中
'request' => [
'baseUrl' => '',
],