0

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]
J.B.J.
  • 440
  • 1
  • 8
  • 15
  • What did you actually wanted to say by => "root" of my project. Did you try to say the base url of your project? Are you stuck on any specific problem? – Rakesh Mehta Sep 22 '22 at 15:16
  • So the particular problem i'm stuck on 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 xD – J.B.J. Sep 22 '22 at 15:24
  • That's why I doubted.. Edit the .htacess at your cakePHP projects root directry and add the base url like RewriteBase /myProject – Rakesh Mehta Sep 22 '22 at 15:28
  • This just gives a server error - checking logs it errors out due to too many internal redirects? – J.B.J. Sep 22 '22 at 15:32
  • Can you post both the .htaccess (the one at the root and the one inside webroot) – Rakesh Mehta Sep 22 '22 at 15:34
  • Done - updated the question. Thank you so much for trying to help, been stuck for days – J.B.J. Sep 22 '22 at 15:37

2 Answers2

0

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.

mhaendler
  • 124
  • 5
0

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

Rakesh Mehta
  • 519
  • 2
  • 9
  • I did not change anything in the .htaccess files, but i went into the /app/config/app.php and set the baseurl like so: 'baseUrl' => '/myProject' and now it works! Thank you so freaking much!!! – J.B.J. Sep 22 '22 at 16:02