【发布时间】:2017-03-27 21:22:14
【问题描述】:
我在 Yii2 PHP 站点上有两个控制器。第一个是站点控制器。第二个是博客控制器。我有这个现有的重定向设置。
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule ^.*$ frontend/web/index.php
这很好用,网址重定向如下:
/site/about 重定向到/frontend/web/index.php/site/about
我现在正在尝试设置行为来重定向我的博客帖子。
目前,这些帖子在/blog/view?slug=SLUG 可见。我希望它们在/blog/SLUG 上可见。我想让/blog 重定向到/blog/index。
我不擅长正则表达式和 htaccess 重写。我尝试了任意数量的衍生产品,但无法正确重定向网址。
/blog/test 应该重定向到 /frontend/web/index.php/blog/view?slug=test 和 /blog/ 或 /blog 应该重定向到 /frontend/web/index.php/blog/index。
有人可以帮忙吗?我最近(失败)的尝试是:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ frontend/web/index.php/blog/view?slug=%1
# otherwise forward it to index.php
RewriteRule ^.*$ frontend/web/index.php
如果任何有 Yii2 经验的人想插话,我实际上也可能误解了我当前的重定向。
【问题讨论】:
标签: php .htaccess redirect yii yii2