假设我在用户浏览页面(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 /
还假设网址中的浏览条件顺序很重要(即A / B - 确定,但B / A不正常)
我的.htaccess
文件中有代码
RewriteEngine On
RewriteRule ^/Location-([^/]+)/$ /index.php?Location=$1 [L]
RewriteRule ^/Education-([^/]+)/$ /index.php?Education=$1 [L]
(...)
(...)
RewriteRule ^/Location-([^/]+)/Education-([^/]+)/Sex-([^/]+)/Interest-([^/]+)/$ /index.php?Location=$1&Education=$2&Sex=$3&Interest=$4 [L]
如果我有8个变量,这将变得非常长。
有更聪明的方式实现上述目标吗?可能使用[C] - 链或[N] - 下一个? (URL变量的顺序很重要)
提前致谢
答案 0 :(得分:1)
试试这个:
RewriteRule ^/([^-]+)-([^/]+)/$ /index.php?$1=$2 [L]
RewriteRule ^/([^-]+)-([^/]+)/([^-]+)-([^/]+)/$ /index.php?$1=$2&$3=$4 [L]
RewriteRule ^/([^-]+)-([^/]+)/([^-]+)-([^/]+)/([^-]+)-([^/]+)/$ /index.php?$1=$2&$3=$4&$5=$6 [L]
RewriteRule ^/([^-]+)-([^/]+)/([^-]+)-([^/]+)/([^-]+)-([^/]+)/([^-]+)-([^/]+)/$ /index.php?$1=$2&$3=$4&$5=$6&$7=$8 [L]
...