私はYii2 PHPサイトに2つのコントローラを持っています。最初はSiteControllerです。 2番目はBlogControllerです。私はこの既存のリダイレクト設定を持っています。単一のYii2コントローラにhtacessリダイレクトを追加
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
これがうまく機能、およびURLはそうのようなリダイレクト:
/site/about
は、私は今、私のブログの記事をリダイレクトするために行動をセットアップしようとしています/frontend/web/index.php/site/about
にリダイレクトします。
現在、投稿は/blog/view?slug=SLUG
に表示されています。私はそれらを/blog/SLUG
に見せたい。 /blog
を/blog/index
にリダイレクトします。
私はregexとhtaccessの書き換えにひどいです。私は任意の数のデリバティブを試してきましたが、正しくリダイレクトするURLを取得できません。 /frontend/web/index.php/blog/index
にリダイレクトする必要
/blog/test
は/frontend/web/index.php/blog/view?slug=test
と/blog/
または/blog
にリダイレクトすべきです。
助けてもらえますか?私の最新の(失敗)の試みは、次のとおりです。
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の経験を持つ誰もが、私は実際にも私の現在のリダイレクトを誤解することができる、チャイムしたい場合。
これは理事長です!私はapiコンポーネントのルールを使用しています。 –