Possible Duplicate:
Rewrite all queries to not need the .php extension using a mod_rewrite RewriteRule
I am learning how to create a website, and would like some help.
I have this path in the wamp folder: C:\wamp\www\Personal_site\Root_fold\index.php (the main file starts here).
I want to have cleanurls for this file: C:\wamp\www\Personal_site\Root_fold\Tutorials\C_sharp\C_loginapp.php, and I want it to show up as C:\wamp\www\Personal_site\Root_fold\Tutorials\C_sharp\C_loginapp – the same file, but without the .php on the end.
I also want this to happen to every other file that I have in my website – even the index.php – without repeating the rewritecond for each and every file. How do I do that?
By the way, I am running this locally on my computer – no hosting service or anything like that – and also I am creating the .htaccess file by opening it in notepad and saving the file with the name “.htacess”, which means it forces the file to save with the .htacess extension.
Clean URLs go beyond just hiding the
.phpextension. It also needs to incorporate query parameters, so that instead of/article?title=foobarit looks like/article/foobar.This problem was solved over and over and over again. Please don’t participate in the PHP community’s pervasive Not invented here syndrome and use one of the existing solutions available. It will make you a better programmer in general, because today’s programming is about artfully combining existing components with your unique domain logic instead of writing everything from scratch.
UPDATE
Since you are just starting, it might be hard for you to start using a full-blown framework like Symfony2 — but I suggest to use it when you’ll be more comfortable with PHP.
For now, the Silex micro-framework might be a good start for you. It’s very easy to start with. As a simple example, here is your
index.phpfile:And this is your
.htaccess:This is a complete app written in Silex. When you go to
<yourhost>/hello/JackyBoiit will respond withHello JackyBoi.You can do more advanced stuff with Silex — details are in the docs. When you outgrow it, you can naturally graduate to its bigger brother Symfony2.