问题描述
限时送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
吗?我们在我的工作场所使用 Ubuntu
和 Apache
服务器.这也是前端和后端(它们很相似):
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.myapp
和 admin.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
重复上述步骤并更改文件名和 ServerName
、Directory
和 DirectoryRoot
> 分别.
3) Repeat the above steps for the backend
and change the file names and ServerName
, Directory
and DirectoryRoot
respectively.
4) 确保您在 frontend/web
和 backend/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.myapp
或 admin.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:关键词]
发布评论