【发布时间】:2015-05-22 15:32:18
【问题描述】:
我有一个网站,我必须使用 .htaccess 文件将所有请求重定向到处理重定向的 index.php。 我想重写 URL,同时使用 HTTPS。如果没有 HTTPS,它可以正常工作。
来自没有 HTTPS 的工作 .htaccess 的代码。浏览器得到这个输入:alert/create
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]
这工作正常,但没有 HTTPS。浏览器 URL 变为 http://localhost/mypage/alert/create,,这就是我想要的。
我找到了一个允许我使用 HTTPS 的解决方案:
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ https://%{SERVER_NAME}/mypage/index.php?controller=$1&action=$2&id=$3 [NC,L]
页面导航就像一个魅力,但浏览器显示的 URL 是这样的:
https://localhost/mypage/index.php?controller=alert&action=create&id=
请求的处理方式如下:
public function __construct($urlvalues) {
$this->urlvalues = $urlvalues;
if ($this->urlvalues['controller'] == "") {
$this->controller = "home";
} else {
$this->controller = $this->urlvalues['controller'];
}
if ($this->urlvalues['action'] == "") {
$this->action = "index";
} else {
$this->action = $this->urlvalues['action'];
}
}
我需要一些提示。我一直在寻找整个互联网而没有解决我的问题...... 如果我可以使用 .htaccess,但以另一种方式实现 HTTPS,那也将是完美的。 用 PHP 编写的服务器代码,在 apache2 上运行。
【问题讨论】:
标签: php .htaccess https url-rewriting