Yii2:高级应用程序中的独立前端和后端在 XAMPP 上不起作用

编程入门 行业动态 更新时间:2024-10-21 15:39:28
本文介绍了Yii2:高级应用程序中的独立前端和后端在 XAMPP 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我只想通过 www.domain\admin 访问后端部分,通过 www.domain 访问前端.我在我的根 .htaccess 中所做的是:

I simply want to access the backend part via www.domain\admin and frontend by www.domain. What I did in my root .htaccess is :

Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]

RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1

它重定向到前端,但不能与后端正常工作.无法意识到问题出在哪里,因为我在工作中使用了相同的配置行,并且一切正常.可能是因为 XAMPP 吗?我们在我的工作场所使用 UbuntuApache 服务器.这也是前端和后端(它们很相似):

It redirects to the the frontend but doesn't work properly with the backend. Can't realize what is the problem because I am using the same lines of configurations at work and there everything is OK. Can it be because of the XAMPP? We work on Ubuntu and Apache server at my workplace. This is the frontend and backend ( they are similar ) also :

AddDefaultCharset utf-8

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on


# Make the backend accessible via url: http://site/admin
RewriteRule ^admin$ $admin.php [L]

# 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


RewriteRule ^static - [L]

我做到了!我在 httpd-vhost.conf 中设置的是:

<VirtualHost *:8080>
    ServerName fitness
    DocumentRoot "c:/xampp/htdocs/fitness/frontend/web"
</VirtualHost>

问题是我将请求重定向到 frontend/web htaccess 但我真正需要的是根 .htaccess.所以我将 DocumentRoot 更改为 c:/xampp/htdocs/fitness.

And the problem was that I was redirecting my request to the frontend/web htaccess but what I really needed was the root .htaccess. So I had changed the DocumentRoot to c:/xampp/htdocs/fitness.

推荐答案

当我在我们有 ubuntu 的办公室工作时,我总是使用以下方式设置新项目,并且它总是完美运行.

I always use the following way when setting up a new project when I am working in the office where we have ubuntu and it always works perfectly.

按照以下步骤,创建 2 个名为 www.myappadmin.myapp

Follow these steps below, and create 2 virtual hosts with the name www.myapp and admin.myapp

1) 打开终端并输入

sudo cp/etc/apache2/sites-available/000-default.conf/etc/apache2/sites-available/www.myapp.conf.sudo nano/etc/apache2/sites-available/www.myapp.conf.

文件打开后添加以下代码.

add the following code once the file opens.

<VirtualHost *:80>
       ServerName www.myapp
       DocumentRoot "/path/to/project/root/frontend/web"

       <Directory "/path/to/project/root/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

           # use index.php as index file
           DirectoryIndex index.php

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

2) 关闭 &保存文件,然后在终端写入

2) Close & save the file and then in terminal write

sudo a2ensite www.myapp.conf打开主机文件 sudo nano/etc/hosts 并在最后添加新行 127.0.0.1 www.myapp.重启apachesudo service apache2 restart sudo a2ensite www.myapp.conf open hosts file sudo nano /etc/hosts and add in the end on a new line 127.0.0.1 www.myapp. Restart apachesudo service apache2 restart

3) 对 backend 重复上述步骤并更改文件名和 ServerNameDirectoryDirectoryRoot> 分别.

3) Repeat the above steps for the backend and change the file names and ServerName, Directory and DirectoryRoot respectively.

4) 确保您在 frontend/webbackend/web 中有一个 .htaccess 文件,并使用以下

4) Just make sure you have a .htaccess file in the frontend/web and backend/web with the following

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

就是这样,除了这些之外,您不需要任何其他 .htaccess 文件,现在在浏览器中输入 www.myappadmin.myapp 并查看它是否有效.

And thats it you wont need any other .htaccess file other than these now type in the browser www.myapp or admin.myapp and see it working.

这篇关于Yii2:高级应用程序中的独立前端和后端在 XAMPP 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:17:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上不   应用程序   后端   独立   高级

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!