Home > front end >  XAMP / Apache - Folders in htdocs as root?
XAMP / Apache - Folders in htdocs as root?

Time:09-23

i'm trying to set up a local development environment using XAMP as my localhost.

My issue is, that i place my projects in sub-folders in the htdocs folder.

This means my directory structure is:

localhost/myProject/index.php

However, that also means the "root" of my project is "localhost" and not "localhost/myProject" as i want it to be.

Any advice on how i fix this?

For total clarity, the reason why i wanna fix it is that i use CakePHP, and it has a structure like: "root/controller/action", but since it is placed in a folder in htdocs, i access it like: "localhost/myProject/controller/action" - the issue is, that it thinks "myProject" is the controller to look for. This is what i am trying to fix. If you have any ideas, please, for the love of god help me

HTACCESS UPDATE

Root .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]

webroot .htaccess

<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]

CodePudding user response:

You have got rewrite engine twice in the root .htaccess. Go back to your default htaccess (If you don't have a backup copy, get it from a fresh cakephp project).

And then try to set project root at your config file (/app/Config/core.php)

Configure::write('App.fullBaseUrl', 'http://example.com');

Change this to your base url and update me..

CodePudding user response:

Thats nothing to "fix", because that's the expected behaviour. For that instance you can create VirtualHosts where you tell your apache where the DocumentRoot of your project is, linked to a "unique" hostname in your browser.

Here is an example how to do it using windows as your OS. How To Set Up Apache Virtual Hosts on XAMPP (Windows)

Here is a quick example how such a virtual host looks like:

<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>

You also want to edit your hosts file, but everything is explained in the Topic i linked.

Depenging on your OS, the pathes my differ.

  • Related