【问题标题】:.htaccess with database.htaccess 与数据库
【发布时间】:2011-09-11 17:20:07
【问题描述】:

我怎样才能做到这一点 mydomain.com/ -> mydomain.com/profile.php?username=

现在您可以通过诸如 domain.com/ 之类的 url 开始搜索

我的 htaccess 文件是

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=search&val=$1 [QSA,L]

我可以在php文件中理解

$val = $_GET['val'];
if($c->userNameCheck($val))
{
    header("Location:".$url."/profile.php?username=".$val);
}

但我不想显示 profile.php

【问题讨论】:

  • 为什么不domain.tld/search/yodadomain.tld/users/yoda

标签: php .htaccess mod-rewrite


【解决方案1】:

您可以简单地将规则替换为:

RewriteRule ^(.*)$ profile.php?username=$1 [QSA,L]

但是,由于您不会执行 index.php 文件,因此不会调用 userNameCheck 方法。我假设它会检查所提供的参数是否是有效的用户名——要使其按照修改后的规则运行,您必须将该调用移至 profile.php 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 2020-07-04
    • 2015-05-25
    • 2014-02-12
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多