Advanced的URL中删除前端

Advanced的URL中删除前端

本文介绍了如何从Yii2 Advanced的URL中删除前端/网络,以便在使用Url :: to时不会出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了.htaccess文件,以防止前端/网络出现在url中,但是当我通过Url :: to saet链接时,它出现在url中.这是我在根目录下的.htaccess文件:

I have written .htaccess files to prevent frontend/web from appearing in url but when I saet links through Url::to it appears in url.This is my .htaccess in root directory:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
</IfModule>

<IfModule mod_rewrite.c>
    # deal with admin first
    RewriteCond %{REQUEST_URI} ^/(admin)
    RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
    RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]

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

    RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
    RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
    RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
    RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
    RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
    RewriteRule ^(.*)$ frontend/web/$1 [L]

    RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
    RewriteCond %{REQUEST_URI} !index.php
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ frontend/web/index.php
</IfModule>

这是frontend/web目录中的.htaccess文件:

This is .htaccess file in frontend/web directory:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

请帮助我,我不知道该怎么办.

Please help me I have no idea what to do.

推荐答案

在Apache的httpd.conf文件或虚拟主机配置中使用以下配置.请注意,您应将path/to/frontend/web替换为frontend/web的实际路径.

Use the following configuration in Apache's httpd.conf file or within a virtual host configuration. Note that you should replace path/to/frontend/web with the actual path for frontend/web.

# Set document root to be "frontend/web"
DocumentRoot "path/to/frontend/web"

<Directory "path/to/frontend/web">
    # use mod_rewrite for pretty URL support
    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

    # ...other settings...
</Directory>

Yii2文档

这篇关于如何从Yii2 Advanced的URL中删除前端/网络,以便在使用Url :: to时不会出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:00