我正在构建一个支持以下功能的迷你框架:
mysite.com/template/
mysite.com/template/action/
mysite.com/template/action/model/
用作 Bootstrap :
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 的一部分,它需要特殊条件。
关于php - htaccess URL 重写最大参数长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11778474/