【发布时间】:2017-12-18 10:49:50
【问题描述】:
首先:如果您对此问题有更好的标题,请告诉我。 您好,我有一个使用 get 变量加载内容的网站。 让我给你解释一下。
我的索引 php 文件:
<?php
#check if get parameter page exists
#check if file exists
require $_GET['page] . '.php'; //if it exists require its content
?>
这样,用户可以访问我的网站并编写如下网址:
http://localhost/loremipsum?page=home
http://localhost/loremipsum?page=help
但为了获得更清晰的网址,我编辑了我的 .htaccess 文件以获取类似以下网址:
http://localhost/loremipsum/home
http://localhost/loremipsum/help
.htaccess: 重写引擎开启 RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 重写规则 ^(.*) /loremipsum/?pg=$1 [L]
但我到了需要其他参数的地步,对于下一个 url,我希望将 userpreferences 作为 page 参数,将 something 作为 fav 参数
这样的网址可以工作:
http://localhost/loremipsum/userpreferences&fav=something
但目标是获得这样的网址:
http://localhost/loremipsum/userpreferences/something
问题是我尝试过的任何方法都不起作用,这是我认为它应该起作用但它没有:
RewriteRule ^(.*)/userpreferences/(a-zA-Z0-9)+ /loremipsum/?pg=$1&fav=$2 [L]
更新:
我知道只有在页面参数等于 userpreferences 并且我正在考虑这样做时才应该应用此规则
RewriteRule ^userpreferences/(a-zA-Z0-9)+ /loremipsum/?pg=userpreferences&fav=$1 [L]
但它不起作用,似乎用户首选项不是字符串,我收到服务器错误。
【问题讨论】: