2014-11-25 66 views
1

我的网址,我想访问不同:多个GET PARAMS

原文:mywebsite.com/index.php?page=index

新:mywebsite.com/index

我做与此的.htaccess:

RewriteEngine on 

# The two lines below allow access to existing files on your server, bypassing 
# the rewrite 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule (.*) index.php?page=$1 [QSA] 

下一URL(从指数挂钩):

原文:mywebsite.com/index.php?page=hotel &酒店= 5

新:mywebsite.com/hotel/5

我发现有关多PARAMS一些信息,但我不能让他们上班。

回答

3

您可以使用一个新的规则2个参数:

RewriteEngine on 
RewriteBase/

# The two lines below allow access to existing files on your server, bypassing 
# the rewrite 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 

RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA] 

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&hotel=$2 [L,QSA] 
+1

作品,谢谢。你介意解释“RewriteBase /”和“RewriteRule^- [L]”吗? – PrimuS 2014-11-25 11:35:22

+0

'RewriteBase /'是可选的,但在这里很好。 'RewriteBase'基本上从.htaccess的当前目录设置文件的路径。 'RewriteRule^- [L]'表示对于上述条件“无所作为”,即如果请求是针对文件/目录,则忽略其余规则。 – anubhava 2014-11-25 11:37:21

+0

现在我想用第三个参数“扩展”规则,现在不行,你能告诉我为什么吗? 'RewriteRule ^([^ /] +)/([^ /] +)/?$ index.php?page = $ 1&hotel = $ 2&vars = $ 3 [L,QSA]' – PrimuS 2014-11-26 10:33:23