What's the code should behind this situation?

2019-09-15 14:37发布

This is the second time I'm asking here about it. I shall try to make it easier to give you the answer.

This is all about rewriteing rule. First of all, have a look below:

The following 4 php script is related to account managing of my php login script.

  1. account.php
  2. login.php
  3. signup.php
  4. logout.php

More details about the scripts:

  1. Accout.php has 4-5 pages based on GET request. E.G. ?page=edit, ?page=view etc.

  2. Login.php has only 2 pages, ?action=login and ?action=block.

  3. Signup.php has 3 pages, ?page=process, ?page=process&step=1,2.

  4. logout.php has only one page.

That's a part of my script. Now I'm interested to rewrite the ugly url. I want all the page has 'account' prefix.

  1. account/edit
  2. account/view
  3. account/login
  4. account/login/blocked
  5. account/create
  6. account/create/step/1
  7. account/create/step/2
  8. account/logout

I think I have cleared my question as much as I can. I have tried a lot but get failed. I hope you guys have the answer for me for "How could I do that?" or "What's the code should behind this situation?"

Please, I really need your help badly.

[Edit]

Thanks for your support @JonLin. Thanks a lot. But I need one more help from you. I hope if you help here i could do others.

Now i have,

  1. forum.php?fid=1&p=2
  2. thread.php?tid=1&p=2

(its not only 1 or 2, its [(0-9)+] )

How to do it like this

  1. forum/f1/anything/page-2
  2. forum/t1/anything/page-2

I've tried your signup.php code with a little edit, but its not working.

All of my pages of the script is formatted like this, any.php?xid=n&p=n ( n != 1 or n > 1 ).

So i want the same prefix used for any.php, that related to the any.php, for i.e. any.php has a book.php i want the url like this, any/a1/anything/page-2 and any/b1/anything/page-2 ( page-n will be shown when n > 1 )

Please help me here, I am stuck here. Thank you very much for your friendly help.

1条回答
放荡不羁爱自由
2楼-- · 2019-09-15 14:57
RewriteEngine On

# to account.php
RewriteRule ^account/edit/?$ /account.php?page=edit [L]
RewriteRule ^account/view/?$ /account.php?page=view [L]
#etc... 

# to login.php
RewriteRule ^account/login/?$ /login.php?action=login [L]
RewriteRule ^account/login/blocked/?$ /login.php?action=block [L]

# to signup.php
RewriteRule ^account/create/? /signup.php?page=process [L]
RewriteRule ^account/create/step/([12])/?$ /signup.php?page=process&step=$1 [L]

# to logout.php
RewriteRule ^account/logout/?$ /logout.php [L]
查看更多
登录 后发表回答