我正在从头开始建立一个网站。一切都在 MySQL 中,所有代码、元数据、js 代码、CSS、正文内容,一切。为此,我创建了一个基于 domain.com/index.php 提供的变量呈现 HTML 页面的类。
根据我不久前找到的一个博客,我以这种方式做这件事很乏味。它带有完整的教程。不幸的是,我再也找不到它了。
无论如何,我的“主”表URL's
配置如下:
| subdomain | category | subcategory | page | extension |
-----------------------------------------------------------------------
| | properties | houses | downtown-la | html |
| properties | houses | downtown | | / |
| ch | properties | houses | downtown-la | html |
| jp | properties | houses | downtown-la | html |
| jp.properties | houses | downtown | | / |
| ch.properties | houses | downtown | | / |
当然,该表有更多的字段,如 pageID.,我还有其他表来定义基于语言、页面标题、描述、关键字等的内容。
我的目标是:
- 让 index.php 将所有 uri/url 请求处理成段。
- 识别用户是否键入了子域/子子域。
- 将这些值传递给 MySQL,以检查页面是否存在。
- 将结果分配给 $status(1 表示“找到的页面”| 0 表示“未找到的页面”)
- 如果 url/page 存在,则将页面的 id 传递给 $id,以便该类可以呈现页面(通过 MySQL)
$subdomain = 'properties'; $sub-subdomain = null; $domain = 'domain,com'; $category = 'houses'; $subcategory = 'downtown'; $ext = '/'; // url in browser: properties.domain.com/houses/downtown/ // some php code here to process url (because there's no folders. Only root/index.php) include('class-page.php'); switch ($status) { Case 1: $html =new page::create($id); echo $html; break; case 0: $html =new page::create(404); //php code to rewrite url as: www.domain.com/error/404.html echo $html; }
如您所见,我想处理 index.php 中的所有页面并让用户认为他们正在访问 www.domain.com/category/subcategory/page.html 中的页面
问题是,我不知道如何在 php 中处理 url/uri,而不是如何在不重定向的情况下保持 url 不变。我想用 php 和很少的 .htaccess 来完成这个壮举(或者最好没有)。