URL Rewriting - PHP & MYSQL: NOVICE TO NINJA

I think you may be having a problem identifying which folder is the “root”.

I have seen them named differently but IIRC, with XAMPP you will not have a folder named “public_html” but it will be named “htdocs”.

This is the “base” folder that HTTP requests for the domain will go to.

For example, if there is an “index.php” file inside the htdocs folder, and you point your browser to “http://localhost” or “http://127.0.0.1” it would be the index.php file that opened in your browser.

The htdocs folder is where you want to put the htaccess file.

2 Likes

I suppose it depends upon your XAMPP set up.
Bearing in mind the book uses a VirtualBox / Vagrant setup, things may be a little different.

I’ve not used XAMPP, but presuming it works similar to WAMP, that creates a www folder as its root, which is accessed at localhost.
But then there is also the option to create any number of virtual hosts which may have a root anywhere you choose, which is the preferred option, allowing multiple projects to act as individual “virtual” sites.

Maybe simplify things until you find your root.
In the location you think may be the root, create a simple “Hello World” type index.php then see if it shows up.
Once you have nailed down your root location, then start adding the code from the book into the correct relative locations from the root.

4 Likes

My website’s folder name is “jokes1”. The path of it is: C:\xampp\htdocs\jokes1.

.htaccess file is in “jokes1”.

When I open http://localhost/jokes1/public/index.php the webpage is opening without any css styles (it means that (jokes.css in C:\xampp\htdocs\jokes1\public is not recognizes) and I have these errors:

Notice: Undefined variable: page in C:\xampp\htdocs\jokes1\public\index.php on line 54

Notice: Undefined variable: page in C:\xampp\htdocs\jokes1\public\index.php on line 60

Warning: include(C:\xampp\htdocs\jokes1\templates): failed to open stream: Permission denied in C:\xampp\htdocs\jokes1\public\index.php on line 6

Warning: include(): Failed opening ‘C:\xampp\htdocs\jokes1\public/…/templates/’ for inclusion (include_path=‘C:\xampp\php\PEAR’) in C:\xampp\htdocs\jokes1\public\index.php on line 6

All files from (https://github.com/spbooks/phpmysql6/tree/CMS-Controller-Rewrite) and nothing was changed

I believe the folder named “public” contains files that go into the “htdocs” folder and that the “classes”, “includes” and “templates” folders are “siblings” of the htdocs folder. That is, not inside but “next to” so they can be accessed by code, but not by HTTP requests in order to have better security. If folders with those names exist use them, else create them.

eg. the directory structure would be like:

C/ 
  xampp/ 
  various-other-files-and-folders/ 
  htdocs/ 
    .htaccess 
    index.php
    other-files/folders-inside-the-public-folder 
  classes/ 
    files/folders-inside-the-classes-folder 
  includes/ 
    files/folders-inside-the-includes-folder 
  templates/ 
    files/folders-inside-the-templates-folder 

If any more familiar know this to be an incorrect assumption please correct me.

2 Likes

In sample project index.php is located in public directory, but I have created directory structure as you described, unfortunately it didn’t help

Op, I would suggest you use Laragon instead of XAMPP. It automatically creates a host from directorys in the www root. You can then access your project as http://myproject.test instead of localhost/myproject/public/. It will be an easy fix for the problem you are having.

I used XAMPP for many years. Laragon works much better.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.