不同的PHP文件的多个虚荣URL?

时间:2012-12-24 09:19:56

标签: php .htaccess web

我正在尝试构建一个网站,其中包含以下需要虚荣网址的页面,

  • account.php
  • questions.php
  • profile.php

我需要显示

www.mysite.com/account?req=settings
www.mysite.com/account?req=questions
www.mysite.com/account?req=answers

如下

www.mysite.com/account/settings
www.mysite.com/account/questions
www.mysite.com/account/answers

对于其他文件,我需要以下内容,

等: - www.mysite.com/questions?id=0484684

作为

www.mysite.com/questions/0484684

www.mysite.com/profile?id=123456

作为

www.mysite.com/profile/123456

有人会帮助我,因为我真的需要这样做。

我也想从网址中删除.php扩展名。

我想说我没有htaccess文件的经验。

感谢您的帮助,它确实有效!!!

2 个答案:

答案 0 :(得分:4)

.htaccess文件中,添加以下规则:

RewriteEngine on
RewriteBase /

RewriteRule ^account/([^/\.]+)/?$ account.php?req=$1 [L,NC,QSA]
RewriteRule ^questions/([^/\.]+)/?$ questions.php?id=$1 [L,NC,QSA]
RewriteRule ^profile/([^/\.]+)/?$ profile.php?id=$1 [L,NC,QSA]

如果您将来需要这些规则,您应该可以根据这些规则的工作方式添加新规则。

答案 1 :(得分:0)

你会想要使用一个.htaccess文件与PHP结合进行复杂的操作,我写了一篇关于在SO上提出类似问题后重写URL的文章:

http://tomsbigbox.com/elegant-url-rewriting/

相关问题