【问题标题】:How to use htaccess to make profile links look like Facebooks如何使用 htaccess 使个人资料链接看起来像 Facebook
【发布时间】:2014-11-13 08:24:27
【问题描述】:

我想知道如何配置我的 .htaccess 文件以呈现以下格式的个人资料页面:firstname.lastname.id。 Facebook的个人资料链接看起来像这样的方式,如果有人知道如何制作,那将非常受欢迎! :)

PS。抱歉解释的不好!我是瑞典人!

【问题讨论】:

  • 考虑到 .htaccess 文件本身不支持条件编码,确切地说...您可能不得不将用户跳转到可以处理该问题的脚本页面。
  • @durbnpoisn 那么您对如何做到这一点有什么建议吗?

标签: php .htaccess hyperlink profile


【解决方案1】:
php_flag magic_quotes_gpc off
AddType 'text/html; charset=UTF-8' html

Options -Indexes -MultiViews
RewriteEngine on

# list of extensions which won't be running the index.php file
RewriteCond %{REQUEST_URI} !(.*)\.(css|js|gif|jpg|png|txt|ico)$

# everything else will run index.php file, where you can check your URL string if it matches any of your user profile name
RewriteRule .* index.php

然后在php中:

$requestedURL = 'first_name.last_name.23423';

$matches = array();
$res = preg_match_all('/([a-zA-Z0-9_]+).([a-zA-Z0-9_]+).(\d+)/', $requestedURL, $matches);

echo "<pre>";
var_dump($matches);
echo "</pre>";
die();

$matches 在哪里:

array(4) {
  [0]=>
  array(1) {
    [0]=>
    string(26) "first_name.last_name.23423"
  }
  [1]=>
  array(1) {
    [0]=>
    string(10) "first_name"
  }
  [2]=>
  array(1) {
    [0]=>
    string(9) "last_name"
  }
  [3]=>
  array(1) {
    [0]=>
    string(5) "23423"
  }
}

【讨论】:

  • 如何在 SQL 查询中使用它?我不擅长 PHP,所以我不知道 :(
  • 喂?如何将不同的数组分配给变量?
  • $firstName = $matches[1]; $lastName = $matches[2];
  • 关于 SQL,你最好再写一篇文章,包括你目前所拥有的内容
  • 谢谢伙计,除了 index.php 加载时如何防止 profile.php 加载?我可能对 a*s 感到很痛苦,但我对 htaccess 不是很熟悉 :(
猜你喜欢
  • 2012-02-19
  • 1970-01-01
  • 2016-12-21
  • 2012-01-20
  • 2012-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-16
相关资源
最近更新 更多