I have all downloaded [CMS-Controller-Rewrite] sample files from the github (https://github.com/spbooks/phpmysql6/tree/CMS-Controller-Rewrite) and I have Apache server. So, I created a file called [.htaccess] in the new [public_html] directory with the following contents:
conf
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [NC,L,QSA]
(all instructions from the book “PHP & MYSQL: NOVICE TO NINJA” page 375). Doing these steps, the project does not work anymore - all links are not correct.
I presume that my URL rewriting is wrong.
Could anybody explain how to do URL rewriting correctly, thanks.
Removing “conf” do not help. My other question is:
I have all downloaded [CMS-Controller-Rewrite] sample files from the github (https://github.com/spbooks/phpmysql6/tree/CMS-Controller-Rewrite) and I have Apache [XAMPP] server. I presume that the code of all these files is correct. But it doesn’t work neither with .htaccess file (code from the book) neither without it.
I don’t see the .htaccess file on github, I would expect it to be in the public folder, maybe @TomB did not include the .htaccess
I just tried the code exactly as in the book and it appears to work as expected (using WAMP).
Check that the file is named correctly, some editors will try and add an extension.
Also I sometime find when editing .htaccess that it sometimes caches so I don’t see changes I made. I have spend many times of frustration, doubting my abilities in htaccess, when all along it was still using an older version of the file.
I tested the code on a local version of a site I manage. So strictly speaking, it’s not the exact same as in the book, because there was already other stuff in the htaccess. I just pasted the code in near the top.
But it certainly does what it is supposed to.
Without the code, a nonexistent page gives a 404. With the code, it redirects to the homepage.
If you are getting 404 it means the .htaccess file is probably not being recognized. Make sure it’s in your public_html (or whatever you have your public directory configured as) directory l, it’s correct named, the server is correctly configured with mod rewrite enabled and allows htaccess files.
I have root directory (http://localhost/phpmysql6-CMS-Controller-Rewrite) in which all sample folders (classes, includes, public, templates) and files are located. index.php is located in public directory so I’ve put .htaccess file in public directory. The code of .htaccess is:
You will need to move everything up two levels so that the website is on http://localhost/ and everything that was in the public directory is in the website’s root directory, then the rest of the files are not public.
My website’s folder name is “phpmysql6-CMS-Controller-Rewrite”, so it is on http://localhost/ already. I described it in previous post. Are you sure that this code of .htaccess is ok?