Yii2 htaccess的 - 如何隐藏前端/网络和后端/网络COMPLETELY [英] Yii2 htaccess - How to hide frontend/web and backend/web COMPLETELY

查看:620
本文介绍了Yii2 htaccess的 - 如何隐藏前端/网络和后端/网络COMPLETELY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我是pretty的接近。我有htaccess的重定向到网站(前端/网络)和/管理路径(后端/网络)。该网站显示正常,CSS文件加载等。

I think I am pretty close. I have the htaccess redirecting to the website (frontend/web) and the /admin path (backend/web). The site appears fine, CSS files loading, etc.

如果你去:的http://本地主机/ yii2app / - 它加载网页,并且不会在地址栏中重定向,但页面显示前端/网络中的所有的URL。

If you go to: http://localhost/yii2app/ - it loads the homepage, and doesn't redirect in the address bar, but the page shows frontend/web in all the URLs.

如果你去:的http://本地主机/ yii2app /管理 - 它加载后台登录页面,但它立即重定向到/后端/网络/网站/登录在地址栏(丑陋的)。

if you go to: http://localhost/yii2app/admin - it loads the backend login page, however it immediately redirects to /backend/web/site/login in the address bar (ugly).

问题:在前端/后端路径中,显示的网址(地址栏和页面上的链接)

Problem: The frontend/backend paths are showing in the URLs (address bar, and links on the page).

我需要什么:我想整个网站没有显示前端/后端链接的操作。该项目的根应该拉(不可见)的前端/网络而不表现出来。所以的http://本地主机/ yii2app / 运行我的整个前端和访问http://本地主机/ yii2app /管理/ 运行我的整个后端

What I need: I want the whole site to operate without showing frontend/backend links. The project's root should pull (invisibly) from the frontend/web without showing it.. So http://localhost/yii2app/ runs my whole frontend, and http://localhost/yii2app/admin/ runs my whole backend.

为什么呢?我觉得这个设置是pretty的固体和优雅的,当一台服务器上直播。我希望能够把我的项目文件夹活到一个网站,它的工作只是罚款,而不必有黑客来处理本地VS服务器。

Why? I feel this setup would be pretty solid and elegant when live on a server. I want to be able to push my project folder live to a site and it work just fine without having to have hacks to handle local vs server.

htaccess的在/ yii2app DIR:

htaccess in /yii2app dir:

Options -Indexes
RewriteEngine on

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
    RewriteCond %{REQUEST_URI} admin
    RewriteRule .* backend/web/index.php [L]

    RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
    RewriteCond %{REQUEST_URI} !admin
    RewriteRule .* frontend/web/index.php [L]
</IfModule>

现在的前端和后端的Web目录,它们都具有相同的htaccess的:

Now in frontend and backend web directories, they both have the same htaccess:

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

我不希望看到/前端/ Web或/后端/网络永远)

I do not want to see /frontend/web or /backend/web ever :)

我试过在根的htaccess的添加/管理的URL重写规则的游戏,但它不停地告诉我/管理不存在。我的知道的它不存在,我不希望它存在。我想这是一个相对路径..即:/管理== /后端/网络

I tried to play with the RewriteRule in the root's htaccess to add /admin to the URL, but it kept telling me /admin does not exist. I KNOW it does not exist, and I don't want it to exist. I want it to be a relative path.. ie: /admin == /backend/web.

措辞的另一种方式。我的方式一切都在项目的根(的http://本地主机/ yii2app / )加载前端/网络,但没有表现出来。此外,的http://本地主机/ yii2app /管理加载后台/网页,只是显示的的http://本地主机/ yii2app /管理。显然他们将有其各自的控制器/动作连接于他们。因此,管理员可能看起来像的http://本地主机/ yii2app /管理/网站/登录

Worded another way. I way everything in the project's root (http://localhost/yii2app/) to load frontend/web, but without showing it. Also, http://localhost/yii2app/admin to load backend/web and just showing http://localhost/yii2app/admin. Obviously they would have their respective controller/action attached to them. So admin could look like http://localhost/yii2app/admin/site/login

注:我还没有发挥任何文件。这是A股yii2高级设置,使用的作曲家,并按照文档。我已经打了迄今为止唯一被提及htaccess的文件。

NOTE: I have not played with any of the files. This is a stock yii2 advanced setup, using composer, and following the docs. The only thing I have played with so far are the htaccess files mentioned.

感谢您!

推荐答案

如果你唯一的目标是实现没有曾经看到 /前端/网络 /后端/网络,即使不使用的.htaccess规则,你可以去以下内容:

If your only goal is to achieve not ever seeing /frontend/web or /backend/web, even without using .htaccess rules, you could go for the following:

为什么不直接拔出网​​站文件夹的内容,并把他们的根?只需调整指的是在输入脚本的index.php

Why not just pull out the contents of the web folders and place them in the root? Just adjust the path referring to the framework and config files in the entry scripts index.php.

您的目录结构将是这样的:

Your dir structure would look like:

- yii2app/
    - frontend/
    - backend/
    - common/
    - .. other folders..
    - admin/
        - assets/
        - css/
        - index.php
    - assets/
    - css/
    - index.php

yii2app / index.php文件将如下图所示:

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/frontend/config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/common/config/main.php'),
    require(__DIR__ . '/common/config/main-local.php'),
    require(__DIR__ . '/frontend/config/main.php'),
    require(__DIR__ . '/frontend/config/main-local.php')
);

$application = new yii\web\Application($config);
$application->run();

和您的 yii2app /管理/的index.php 看起来像:

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../common/config/bootstrap.php');
require(__DIR__ . '/../backend/config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/../common/config/main.php'),
    require(__DIR__ . '/../common/config/main-local.php'),
    require(__DIR__ . '/../backend/config/main.php'),
    require(__DIR__ . '/../backend/config/main-local.php')
);

$application = new yii\web\Application($config);
$application->run();

编辑:您的输入脚本,可以看看不同的矿,但你应该得到改变路径找到框架文件,这些例子的想法

your entry scripts could look different to mine, but you should get the idea of changing the paths to find the framework files with these examples.

这篇关于Yii2 htaccess的 - 如何隐藏前端/网络和后端/网络COMPLETELY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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