htaccess - 动态传递随机变量

时间:2014-10-08 00:04:51

标签: .htaccess

我目前的htaccess文件(由@anubhava提供)是

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# load index.php by default
DirectoryIndex index.php

RewriteBase /

# remove trailing slash    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [NE,R=301,L]

# for all other requests load room.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(1|2|3|4|5|6|7|8|9|10|anonymity|similarity|inconspicuous)
RewriteRule ^((?!(index|room)\.php).+)$ room.php?u=$1 [L,NC]

现在的工作方式是,如果有人访问www.example.com,他们将被定向到index.php。如果他们访问www.example.com/anythingelse,他们会被重定向到room.php

我有3个额外的变量可供用户随时传递。他们可能只使用其中的一个,或者可能只使用其中的三个。另外三个变量是

redirect
panic
timeout

如果我在网址中使用全部三个,它看起来像

http://www.example.com/this?panic=0&timeout=3&redirect=google.com

但正如我所说,他们可能只会传递其中一些,所以另一种变化可能是

http://www.example.com/this?timeout=3&redirect=google.com

是否有可能动态(无特定顺序)确定选择了哪些变量,并能够将它们传递给room.php

1 个答案:

答案 0 :(得分:1)

您可以使用上一条规则中的QSA标记传递它们:

RewriteRule ^((?!(index|room)\.php).+)$ room.php?u=$1 [L,NC,QSA]

这会将查询字符串传递给room.php

相关问题