.htaccess - 使用链编写高效的代码,接下来是 url 重定向
假设我在用户浏览页面(www.date.com)上有如下 URL: www.date.com/Location-A/Education-B/Sex-C/Interest-D/
情况是用户只能浏览所有 (4) 个可用标准中的一部分(1 或 2) www.date.com/Education-B/ 或 www.date.com/Sex-C/Interest-E/
另外假设 URL 中浏览条件的顺序很重要(即 A/B - 可以,但 B/A 不行)
我的 中有代码。 htaccess
文件
RewriteEngine On
1 个变量 case
RewriteRule ^/Location-([^/]+)/$ /index.php?Location=$1 [L]
RewriteRule ^/Education-([^/]+)/$ /index.php?Education=$1 [L]
(...)
2 个变量 case
(...)
4 个变量 case
RewriteRule ^/Location-([^/]+)/Education-([^/]+)/Sex-([^/]+)/Interest-([^/]+)/$ /index.php?Location=$1&Education=$2&Sex=$3&Interest=$4 [L]
如果我有 8 个变量,这将变得非常长。
是否有更聪明的方法来实现上述目标?可能使用 [C] - 链或 [N] - 接下来? (URL 变量的顺序很重要)
提前致谢
Suppose I have URLs as following on a user browsing page (www.date.com):
www.date.com/Location-A/Education-B/Sex-C/Interest-D/
The situation is a user may browse only a number (1 or 2) of all (4) available criterias
www.date.com/Education-B/ or
www.date.com/Sex-C/Interest-E/
Also suppose the order of browsing criteria in the URL matter (i.e. A/B - ok, but B/A is not ok)
I had codes in my .htaccess
file
RewriteEngine On
1 variable case
RewriteRule ^/Location-([^/]+)/$ /index.php?Location=$1 [L]
RewriteRule ^/Education-([^/]+)/$ /index.php?Education=$1 [L]
(...)
2 variables case
(...)
4 variables case
RewriteRule ^/Location-([^/]+)/Education-([^/]+)/Sex-([^/]+)/Interest-([^/]+)/$ /index.php?Location=$1&Education=$2&Sex=$3&Interest=$4 [L]
This will get stupidly long if I have 8 variables.
Is there smarter way of achieving above? Possibly using [C] - chain or [N] - next? (the order of URL variables matter)
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: