Reputation: 3424
I have seen on many sites, the structure of the URL is of the form
http://tabsize.com
/user/login
OR
http://tabsize.com
/user/register
http://tabsize.com
/user/account
From user->login OR user->register
So how to you maintain this sort of URL structure?
I am currently using hard-coded type URLs like,
www.example.com/login.php
www.example.com/register.php
I dont think my way is professional, I also want to be able to create the same structure as given in the example above.
How do you achieve it?
Upvotes: 0
Views: 223
Reputation: 9443
You need to make all requests go via your index.php file. That way you can perform a lookup on the path and choose a function to return the response.
eg.
index.php?uri=/user/login/
then inside you index.php file perform the lookup
<?php
$uri = $_GET["uri"];
if ($uri == "/user/login/") {
print "login page";
}
else if ($uri == "/something/else/") {
print "some other page";
}
This way isn't maintainable and I wouldn't recommend it but you get the idea.
Then in your .htaccess you want to remove index.php?uri=
RewriteRule .* index.php?uri=$0 [PT,QSA,L]
Now URLs like this will work http://example.com/user/login/
I would recommend looking into PHP frameworks which already have solutions to this. CodeIgniter and Kohana are good.
Or Django if you know Python.
Upvotes: 0
Reputation: 41855
I think the main reason that you see this structure on many sites is because they use a framework.
And most of the time, user
corresponds to a module, and login
to an action. If your application is big enough, you should consider using a framework.
Upvotes: 0
Reputation: 2808
The easiest way would be using folders and index files:
http://tabsize.com/user/register
->http://tabsize.com/user/register/index.php
http://tabsize.com/user/account
->http://tabsize.com/user/account/index.php
Upvotes: 1
Reputation: 2001
Personaly i using this website, it help's a lot: http://www.generateit.net/mod-rewrite/
Upvotes: 0