简体   繁体   中英

structure of url

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?

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

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.

我个人使用此网站,对您有很多帮助: http : //www.generateit.net/mod-rewrite/

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM