0

My root folder structure is as follows:

enter image description here

I have an index.php as the home page and I want it to load when i simply go to my domain (ex: http://example.com)

Then, I have user.php page that GET data and show the user. current url http://example.com/user.php?u=johndoe

I want it to be http://example.com/johndoe

and I want it to identify other php files and folders without any conflict with above structure.

(http://example.com/about not interpret as http://example.com/user.php?u=about or http://example.com/folder as http://example.com/user.php?u=folder)

I appreciate a SEO friendly answer. Thank you

halfer
  • 19,824
  • 17
  • 99
  • 186
AnushkaM
  • 63
  • 2
  • 10
  • Have you considered using a lightweight framework like slim php to handle your requests? It'll do what you need it to do, and it should be fairly trivial to implement alongside the code you've already written. – Jason May 25 '19 at 13:30
  • 1
    You will probably struggle if you alias `http://example.com/johndoe -> http://example.com/user.php?u=johndoe`. This would need a "catch-all" and thus you would be assuming that anything not specifically recognised is a user. In six months time, when you want to add another object (e.g. groups) then you'll be stuck - unless you don't mind doing various database calls to find out what type of object something is. – halfer May 25 '19 at 16:39
  • 1
    It is much better to use the format of `http://example.com/u/johndoe` or `http://example.com/user/johndoe` so you know what kind of object the user wants (and so you have room for further expansion). You can write some Apache mod_rewrite directives to accomplish this (see the suggested duplicate). – halfer May 25 '19 at 16:40
  • 1
    I agree with @Emma's tag edits, so I have restored them. I have also removed voting advice from this post, which is not of interest to most readers (most readers do not have an account). I recommend being careful about rolling back good edits, and I would note that it takes a bit of experience in order to know what a good edit looks like. – halfer May 25 '19 at 16:44

0 Answers0