在 yii2 中从前端和后端删除 web 文件夹后,从 url 中删除 index.php [英] Remove index.php from url after removing web folder from frontend and backend in yii2

查看:34
本文介绍了在 yii2 中从前端和后端删除 web 文件夹后,从 url 中删除 index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 url 中删除 index.php.我将 .htaccess 放在根目录中,并在 common/config/main-local.php 中写了以下几行.
但是每个 url 都被重定向到后端.

I want to remove index.php from url. I put .htaccess in the root and wrote the following lines in common/config/main-local.php.
But every url is redirected to backend.

我的.htaccess文件:

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 . index.php 

我的common/config/main-local.php文件:

'urlManager' => [
  'class' => 'yii\web\UrlManager',
  // Disable index.php
  'showScriptName' => false,
  // Disable r= routes
  'enablePrettyUrl' => true,
  'rules' => array(
    '<controller:\w+>/<id:\d+>' => '<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
   ),
],

注意:我想从前端和后端删除 index.php.

Note: I want to remove index.php from both frontend and backend.

推荐答案

在 .htaccess 文件中(把 .htaccess 放在 frontend/web 和 backend/web 中)

In .htaccess file(put .htaccess in frontend/web and backend/web )

RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php

在 frontend/config/main.php 和 backend/config/main.php 中:

And in frontend/config/main.php and backend/config/main.php:

'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            ],
    ],

这篇关于在 yii2 中从前端和后端删除 web 文件夹后,从 url 中删除 index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆