【发布时间】:2014-12-11 08:15:15
【问题描述】:
我正在尝试将我的 url 配置文件 URL 重写为干净且不包含参数,至少对用户而言。我正在使用 nginx 服务器,但无法正常工作。
网站示例: http://website.com/subfolder/
个人资料链接: http://website.com/subfolder/profile.php
什么有效: http://website.com/subfolder/profile.php?username=Bobby
我想做什么: http://website.com/subfolder/Bobby
我的网站配置中的代码块:
location /subfolder/ {
if ($query_string ~ "^username=([A-Za-z0-9]+)$"){
rewrite ^/profile.php$ http://website.com/subfolder/%1 redirect;
}
}
【问题讨论】:
-
只是一个提示,您正在做相反的事情,您尝试在内部将带有查询字符串的请求重写为 PHP 无法理解的内容。您需要在 PHP 代码中编写最终 URL,并在 Nginx 内部管理从这个新 url 到查询字符串版本的重写。
标签: php nginx url-rewriting