XAMP / Apache -htdocs中的文件夹是否为根目录?

neekobn8  于 2022-11-16  发布在  Apache
关注(0)|答案(2)|浏览(130)

我尝试使用XAMP作为本地主机来设置本地开发环境。
我的问题是,我把我的项目放在htdocs文件夹的子文件夹中。
这意味着我的目录结构是:

localhost/myProject/index.php

然而,这也意味着我的项目的“根”是“localhost”,而不是我希望的“localhost/myProject”。
有什么建议吗?
为了清楚起见,我想修复它的原因是我使用了CakePHP,它的结构如下:“root/controller/action”,但由于它被放置在htdocs中的一个文件夹中,我像这样访问它:“localhost/myProject/controller/action”-问题是,它认为“myProject”是要寻找的控制器。这就是我正在努力解决的问题。如果你有任何想法,请看在上帝的份上帮助我

HTACCESS更新

根目录.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]

RewriteBase /bakesystem

#Rewrite everything to https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

网页根目录

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

#Rewrite everything to https - disabled on test

#RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
iibxawm4

iibxawm41#

你在根目录. htaccess中得到了两次重写引擎。回到你的默认htaccess(如果你没有备份,从一个新的cakephp项目中得到它)。
然后尝试在配置文件(/app/Config/core.php)中设置项目根目录
配置::write('应用程序完整基本URL','http:example.com');
将此更改为您的基本URL并更新我..

n6lpvg4x

n6lpvg4x2#

这不需要“修复”,因为这是预期的行为。对于这种情况,你可以创建VirtualHosts,告诉你的apache你的项目的DocumentRoot在哪里,链接到你浏览器中的一个“唯一”主机名。
下面是一个使用windows作为操作系统的示例。How To Set Up Apache Virtual Hosts on XAMPP (Windows)
下面是这样一个虚拟主机的快速示例:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot "C:/xampp/htdocs/example
  ServerName example.local
  SetEnv APPLICATION_ENV development
  ErrorLog "logs/example-error.log"
  CustomLog "logs/example-access.log" common
</VirtualHost>

你也想编辑你的主机文件,但一切都在我链接的主题中解释。
根据您的操作系统,路径可能会有所不同。

相关问题