mod_rewrite的扁平链接 [英] Mod_rewrite flat links
问题描述
我想显示我的GET变量平联系。 想从这个改变:
http://mydomain.com/index.php?page=shop&var1=hat&var2=10
到
http://mydomain.com/index.php/shop/hat/10
请记住,没有变量固定的数字,这就是为什么我用VAR1,VAR2,...等
我已经有部分工作的脚本,而只用最多3个变量的作品
的RewriteCond%{ENV:REDIRECT_STATUS} 200
重写规则。* - [L]
重写规则^([^ / \。] +)/ $的index.php?网页= $ 1 [L]
?重写规则^([^ / \] +)/([^ / \。] +)/ $ index.php页面= $ 1安培;?无功= $ 2 [L]
????重写规则^([^ / \] +)/([^ / \] +)/([^ / \] +)/ $ index.php页面= $ 1和2 VAR = $&放大器; VAR2 = $ 3 [L]
????重写规则^([^ / \] +)/([^ / \] +)/([^ / \] +)/ $ index.php页面= $ 1和2 VAR = $&放大器; VAR2 = $ 3及VAR3 = $ 4 L]
所以,首先要记住的mod_rewrite是这样的:
http://mydomain.com/index.php/shop/hat/10
(哪些客户端类型)被改写为
http://mydomain.com/index.php?page=shop&var1=hat&var2=10
(客户端供应什么),但不一定显示像后者。 (除非你把它重定向)
因此,假如您的格式完全地描述如下:
重写规则^指数\的.php /([^ /] +)/([^ /] +)/([0-9] +)$ /index.php?page = $ 1安培; VAR2 = $ 2及VAR2 = $ 3
应该是不错的。
编辑:
呵呵BTW!我没有采取可变数量变量考虑在内。这不应该由mod_rewrite的,我认为进行处理。也许最好的拍摄是重写规则的index.php /(.*)/index.php?call=$1
键,然后用你的脚本中使用/分隔符爆炸。
您只能做,如果你已经知道变量的数量只AFAIK。
I'm trying to display my get variables as flat links. Want to change from this:
http://mydomain.com/index.php?page=shop&var1=hat&var2=10
to
http://mydomain.com/index.php/shop/hat/10
Please keep in mind that there isn't a fixed number of variables, that's why I use var1,var2,...etc
[edit] I already have a partially working script, but works only with max 3 variables
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^([^/\.]+)/?([^/\.]+)/?$ index.php?page=$1&var=$2 [L]
RewriteRule ^([^/\.]+)/?([^/\.]+)/?([^/\.]+)/?$ index.php?page=$1&var=$2&var2=$3 [L]
RewriteRule ^([^/\.]+)/?([^/\.]+)/?([^/\.]+)/?$ index.php?page=$1&var=$2&var2=$3&var3=$4 [L]
So first remember mod_rewrite works like this :
http://mydomain.com/index.php/shop/hat/10
(what the client type) is rewritten to
http://mydomain.com/index.php?page=shop&var1=hat&var2=10
(what the client is served), but not necessarily displayed like the latter. (Unless you make it a redirect)
So assuming your format is completly described here :
RewriteRule ^index\.php/([^/]+)/([^/]+)/([0-9]+)$ /index.php?page=$1&var2=$2&var2=$3
Should be good.
EDIT:
Oh BTW! I did not take the variable number of variable into account. That should not be processed by mod_rewrite I think. Maybe the best shot is to RewriteRule index.php/(.*) /index.php?call=$1
and then use your script to explode using / delimiter.
You can only do it if you already know the number of variable only AFAIK.
这篇关于mod_rewrite的扁平链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!