1

I am developing my application on core php and with that I am working on an application in which the index.php file loads all the template files according to the query. e.g; if user want to go to profile page, the url is, sitename/index.php?q=profile, and for settings page the url is, sitename/index.php?q=settings.

I want to make it clean url, like for profile the url should be like, sitename/profile and sitename/settings.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
vibhav yadav
  • 53
  • 1
  • 11

2 Answers2

3

you could use following code in your .htaccess file to have clean url

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?q=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
Ninja Turtle
  • 1,293
  • 2
  • 24
  • 50
  • Thankyou vinit for you answer, But I have tried this code and this seems not be working in my xampp nor even in godaddy. – vibhav yadav Jun 06 '16 at 07:25
  • you have to enable "mod_rewrite" in your apache configuration. – Ninja Turtle Jun 06 '16 at 08:43
  • Hey Vinit, thank you for the codes, I need to ask you something. This code works fine where there is something like, sitename/index.php?q=settings but if there is url like, sitename/index.php?q=settings/1234/xyz, it throughs 404 error, how to resolve that? – vibhav yadav Jun 24 '16 at 17:41
0

Either shift to MVC architecture and define your routes there accordingly, or use asynchronous requests through JavaScript and fetch and render stuff on the front end itself. Given your situation, both options would take about the same time to implement. Consider other factors of your project and then chose wisely.

sakshamsaxena
  • 107
  • 11