0

I have an older PHP project for a client where we use URLs like: www.domain.com/person1 to show a personalized page for "person1." There is PHP code on index.php in the directory for the domain that uses $_SERVER['REQUEST_URI'] to show the correct page info in place of default index content. This has worked fine for years and continues to work fine on the actual web server. See: http://smd.subitomusic.com/Allapavlova

My issue is that I cannot duplicate this on my local server to do some testing and revisions to other parts of the site. My local server is XAMPP and the web host is Apache on Unix. On the localhost Xampp tries to find a directory with the name "person1" and there isn't one so I get a 404 error instead of the code on index.php running.

Temporarily I've made a work-around by using a GET variable on the localhost (my ondex.php code checks for either $_SERVER['REQUEST_URI'] or GET['page'], so at least I'm able to work on the basic page layout and other functionality. But I'd love to know if there's some little thing I'm overlooking to get it work the same way on localhost as on the remote host.

I hope this makes sense. I've done a lot of searching about this but have had trouble finding the right terms to use to search for how to do this.

  • You need a mod-rewrite rule to forward everything not found as a file or folder to the index.php script. There are many, many examples on the internet. Something to the following should work: ``` RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] ``` – Alex Barker Sep 30 '19 at 23:31
  • Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – gre_gor Sep 30 '19 at 23:38

1 Answers1

0

Create an .htaccess file in the root of your htdocs, and fill it with:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php
ErrorDocument 404 /index.php

Then all not found requests will be forwarded internally to index.php to handle.

  • thank you! I will give this a try and mark it as the answer if I am successful. I really appreciate the pointer as to where/how this happens. – Ellie Armsby Oct 01 '19 at 12:35
  • tried it out on my localhost and it worked (after I added some additional code to account for the slightly different URI on the localhost). Thanks so much, I've been banging my head on it for quite a while. – Ellie Armsby Oct 01 '19 at 17:19