简体   繁体   English

.htaccess重写GET变量

[英].htaccess rewriting GET variables

I have the following page: 我有以下页面:

mysite.com/var2.php?var3

I want to rewrite this so that it goes kind of as follows 我想重写它,以便它如下

mysite.com/var1/var2/var3

In your PHP code (generating HTML), you output /$var1/$var2/$var3 in the href of the link, to get your (second) example. 在您的PHP代码(生成HTML)中,在链接的href中输出/$var1/$var2/$var3 ,以获取您的(第二个)示例。 This is the format that the world will see (an SEF or SEO format). 这是世界会看到的格式(SEF或SEO格式)。

In your .htaccess file (Apache server, or equivalent in other servers), you have statements to rewrite the SEO form (your second example) into the dynamic form (your first example): 在您的.htaccess文件(Apache服务器或其他服务器中的等效文件)中,您具有将SEO表单(第二个示例)重写为动态表单(第一个示例)的语句:

RewriteEngine On
RewriteRule  ^([^/]+)/([^/]+)/([^/]+)$   /$1.php?$2=$3 [QSA]

I'm assuming you meant in that format. 我假设您的意思是那种格式。 There are even some more generic forms floating around on StackExchange that can handle an arbitrary number of var=value pairs. StackExchange上甚至还有一些更通用的形式,可以处理任意数量的var = value对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM