【发布时间】:2021-10-27 03:00:40
【问题描述】:
我有一个站点,其中包含普通用户的 URL https://app.bitlabtech.com/ 和管理员用户 https://app.bitlabtech.com/manager/
客户端登录该站点后,它会重定向到https://app.bitlabtech.com/?page=home,当他们请求另一个页面(如发送邮件)时,URL 看起来像https://app.bitlabtech.com/?page=sendEmail。我想将 URL 重写为 https://app.bitlabtech.com/home 而不是 https://app.bitlabtech.com/?page=home 和 https://app.bitlabtech.com/sendEmail 而不是 https://app.bitlabtech.com/?page=sendEmail。
在 UBUNTU 20.04 apache 服务器上运行的代码。
为了更好地理解,我在这里附上了我的 PHP 代码
public static $page = "page";
public static $folder = PAGES_DIR;
public static function getParam($param = null){
if(!empty($param)) {
return isset($_GET[$param]) && $_GET[$param] != "" ? $_GET[$param] : null;
}
}
public static function cPage(){
return isset($_GET[self::$page]) ? $_GET[self::$page] : "index";
}
public static function getPage(){
$page = self::$folder.DS.self::cPage().".php";
$error = self::$folder.DS."error.php";
return is_file($page) ? $page : $error;
}
public static function getReferrerUrl() {
$page = self::getParam(Login::$_referrer);
return !empty($page) ? "/?page={$page}" : null;
}
}
?>```
【问题讨论】:
-
上面的 PHP 代码无关紧要,您应该发布的是您的 Apache 配置,即 httpd.conf 或 apache2.conf 或 .htaccess,因为您将在 Apache 中使用 mod_rewrite 创建一个重写规则来实现你在找什么
-
PHP 代码用于显示我的 URL 是如何形成的,而不是用于重写。你能再澄清一点吗?
-
您只需要说出您的网址是什么以及您希望它像您在第一段中所做的那样。这些信息足以在 apache 配置文件中创建重写规则。然后你应该发布你当前的 apache 配置是什么,以便人们可以向你展示如何集成 rerite 规则
标签: apache url url-rewriting