I'm running PHP on a shared Apache web server. I can edit the .htaccess file.
I'm trying to simulate a file file structure that is not actually there. For example, I would like for the URL: www.Stackoverflow.com/jimwiggly
to actually display www.StackOverflow.com/index.php?name=jimwiggly
I got halfway there by editing my .htaccess file as per the instructions in this post: PHP: Serve pages without .php files in file structure:
RewriteEngine on
RewriteRule ^jimwiggly$ index.php?name=jimwiggly
This works nicely insofar as the URL bar still displays www.Stackoverflow.com/jimwiggly
and the correct page loads, however, all of my relative links remain unchanged. I could go back in and insert <?php echo $_GET['name'];?>
before each link, but it seems like there might be a better way than that. Additionally, I suspect my whole approach might be off, should I be going about this differently?
I think the best way to do this is to adopt the MVC style url manipulation with the URI and not the params.
In your htaccess use like:
Then in your PHP Script you want to develop a small class to read the URI and split it into segments such as
Use like
http://mysite.com/posts/22/robert-pitt-shows-mvc-style-uri-access
Now in MVC There usually like http://site.com/controller/method/param but in a non MVC Style application you can do http://site.com/action/sub-action/param
Hope this helps you move forward with your application.