微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

htaccess URL重写最大参数长度

我正在建立一个迷你框架,该框架支持

mysite.com/template/
mysite.com/template/action/
mysite.com/template/action/model/

用作引导程序:

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.PHP
RewriteRule .* /index.PHP

但对于任何要求:

mysite.com/template/action/model/**extra/stuff/should/vanish/**

因此,最大URL大小将始终减少任何多余的内容

mysite.com/template/action/model/

解决方法:

你的意思是这样吗?

# if more than 3 nodes deep          v--- the extra stuff should vanish
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/.+ /$1/$2/$3/? [R=301,L]

这将重定向浏览器,以便仅在3个以上的节点中保留3个节点.这可能超出了路由规则.

编辑:

becuase on the forth block this case doesnt hold up: site.com/a/b/c/?d

您需要一个特定的规则来与查询字符串进行匹配,这超出了RewriteRule表达式中的功能.您可以在以上规则之前或之后放置这些规则:

# Check if there's a query string
RewriteCond %{QUERY_STRING} !^$
# if there are exactly 3 nodes, then remove the query string
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$/$1/$2/$3/? [R=301,L]

查询字符串(?之后的所有内容)不是重写引擎中使用的URI的一部分,它需要特殊的条件.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐