Apache 类似Twitter/Facebook的URL(页面、用户名和关于页面)htaccess

Apache 类似Twitter/Facebook的URL(页面、用户名和关于页面)htaccess,apache,.htaccess,Apache,.htaccess,好的,这里有三个Facebook URL: http://facebook.com/about [A Facebook Page] http://facebook.com/zuck [Zuckerberg's Profile] http://facebook.com/like [About Facebook Like Button] 如果我有两页: http://example.com/user.php?u=[username] http://example.com/page.php?p=[p

好的,这里有三个Facebook URL:

http://facebook.com/about [A Facebook Page]
http://facebook.com/zuck [Zuckerberg's Profile]
http://facebook.com/like [About Facebook Like Button]
如果我有两页:

http://example.com/user.php?u=[username]
http://example.com/page.php?p=[pagename]
我已经成功地将user.php重写为http://example.com/[用户名]但之后,当我对页面使用相同的代码,并尝试访问以下页面时http://example.com/[pagename],出现一个用户页面(404页,因为不存在具有该名称的用户,但有一个页面存在)。那么,我应该做些什么来消除这种冲突呢


注意:我不想使用像和这样的URL。请提供帮助。

您需要将所有URL重写为一个单独的php文件,以检测参数是用户名还是页面名。php应该如下所示:

$name = $_GET['name']
if( userNameExists($name) )
  include('user.php');
else if ( pageNameExists($name) )
  include('page.php');
else
  include('404page.php');

您需要在课程之外实现userNameExists()和pageNameExists()。

您可以发布您的htaccess代码吗?无论如何,您可以将该逻辑写入PHP而不是htaccess。htaccess只将参数传递给php解析的对象