0

Good day all,

Today i'm looking at php website and need a link to a new page but despite creating page.php and inserting a link in the header.php. I've found that every time i click a link on the page it simply re-renders the index.php. The links work fine in the live version of the site but not when i run it locally with

php -S localhost:8000

Also this is in the htaccess file

RewriteEngine On

RewriteCond %{HTTP_HOST} ^infinityconnect.co.za [NC]
RewriteRule ^(.*)$ https://www.infinityconnect.co.za/$1 [L,R=301,NC]

#Remove php from pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

I havent worked with php before and i dont know how the routing system works.

Thanks in advance

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Lyle Phillips
  • 197
  • 4
  • 13
  • 1
    Mod_Rewrite is apache. AFAIK, the internal PHP Server does not understand this. – Markus Zeller Apr 02 '20 at 10:11
  • So then must i install xamp and run it on that server ? – Lyle Phillips Apr 02 '20 at 10:13
  • Would be one option. But if you use Windows 10, you can use it in WSL directly (Ubuntu bash). – Markus Zeller Apr 02 '20 at 10:27
  • Im on ubuntu 18.04 and busy installing xamp right now. Gona google how to run the app on xamp and then see if it still re renders index.php. Please stick around im sure that im gona need you're help lol :) – Lyle Phillips Apr 02 '20 at 11:03
  • Okay so installed xamp and now am running the app from htdocs folder. Now when i click my new link it its looking for "http://localhost/ic-website/maps" in the url which is what i want it to do, however, I get "Object not found 404 error". Which doesnt make sense because i did create maps.php inside my project root directory ? – Lyle Phillips Apr 02 '20 at 11:44
  • So now "localhost/ic-website" runs fine it loads the index but every other link breaks and gives the 404 Object not found error. And before when i ran the app with "php -S localhost:8000" then every link just re rendered index.php. Can anyone pls explain this to me – Lyle Phillips Apr 02 '20 at 12:14
  • Your `.htaccess` is incomplete! – Don't Panic Apr 03 '20 at 00:06

1 Answers1

0

It turns out all I had to do is just add .php to any of the files but that is when I manually change the URL. I guess this will work for now

Dharman
  • 30,962
  • 25
  • 85
  • 135
Lyle Phillips
  • 197
  • 4
  • 13
  • That's because your `.htaccess` is incomplete, at least the last line is missing. Exactly what it should be probably depends on the framework you are using (Codeigniter? Laravel?). It is a very standard approach, and just searching on one of those `RewriteCond`s will turn up a lot of hits. [For example this one on SO](https://stackoverflow.com/questions/41575026/why-is-rewritecond-request-filename-d-mandatory) shows the standard way that rule is written. – Don't Panic Apr 03 '20 at 00:06