多个清洁网址变量

时间:2012-08-25 16:04:36

标签: .htaccess

我想知道如何通过url传递几个(两个)值作为一个干净的URL。 我以前做过干净的网址,但从来没有使用多个值,而且似乎没有工作。

这就是网址现在的样子:

http://example.com/?user=Username&page=1

这就是我希望它看起来像

http://example.com/user/Username/page/1

我已尝试过我在这里看过的其他答案,但他们并没有为这笔交易工作。

RewriteEngine On
# Don't match real existing files so CSS, scripts, images aren't rewritten
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d

# Match the first two groups before / and send them to the query string
RewriteRule ^([^/]+)/([^/]+) index.php?user=$1&page=$2 [L] 

感谢。 :) 我顺便使用PHP。 :)

另外,我还能使用$ _GET吗?我是这么认为的,但我也在其他地方说过你不能......:D

1 个答案:

答案 0 :(得分:3)

你错过了几场比赛,试试:

RewriteEngine On
# Don't match real existing files so CSS, scripts, images aren't rewritten
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?$1=$2&$3=$4 [L] 

这将采用如下网址:

http://example.com/a/b/c/d

到URI:

/index.php?a=b&c=d
  

我仍然可以使用$ _GET吗?我是这么想的,但我也在其他地方说过你不能。

在上面的示例中,当您查看$_GET['a']时,您将获得b

相关问题