Php 使用管道和逗号重写URL
如何从如下查询中重写URLPhp 使用管道和逗号重写URL,php,.htaccess,rewrite,Php,.htaccess,Rewrite,如何从如下查询中重写URL http://localhost/index.php?c=vga&av=France|originaly,540-MHZ|freq http://localhost/index.php?c=fructe-congelate&gramaj=1+Kg&av=Romania|Tara%20de%20origine,-18%20grade|Temperatura%20de%20pastrare&brand=Royal 例如: http://
http://localhost/index.php?c=vga&av=France|originaly,540-MHZ|freq
http://localhost/index.php?c=fructe-congelate&gramaj=1+Kg&av=Romania|Tara%20de%20origine,-18%20grade|Temperatura%20de%20pastrare&brand=Royal
例如:
http://localhost/fructe-congelate/gramaj-1+Kg/brand-royal/filtre/Romania|Tara-de-origine,-18|Temperature
我这样做是为了购物车上的过滤系统。这是我目前在.htaccess中的内容:
RewriteEngine On
Options -Indexes
Options +FollowSymLinks
<Files .htaccess>
deny from all
</Files>
RewriteRule ^([A-Za-z0-9_?-]+)/?$ index.php?c=$1 [NC,L]
RewriteRule ^([A-Za-z0-9_?-]+)/filtre/([A-Za-z0-9_?-]+)/?$ index.php?c=$1&av=$2 [NC,L]
重新编写引擎打开
选项-索引
选项+FollowSymLinks
全盘否定
重写规则^([A-Za-z0-9_?-]+)/?$index.php?c=$1[NC,L]
重写规则^([A-Za-z0-9_?-]+)/filter/([A-Za-z0-9_?-]+)/?$index.php?c=$1&av=$2[NC,L]
所有产品过滤器(属性)都存储在$av中,但我有预定义的参数,如gramaj、brand、inoffer、带有附加到sql查询并添加到url的值的页面。您可能需要在重写规则中使用QSA标志。这也会将查询字符串路由到php脚本中
RewriteRule ^([A-Za-z0-9_?-]+)/?$ index.php?c=$1 [NC,L,QSA]
但使用该正则表达式时,不包括管道和逗号。您需要将它们添加到允许的字符列表中:
RewriteRule ^([A-Za-z0-9_?-,\|]+)/?$ index.php?c=$1 [NC,L,QSA]
或者你只要说什么给我:
RewriteRule (.*) index.php?c=$1 [NC,L,QSA]
因为除了字母数字之外,您还有各种特殊字符,所以最好像这样使用
[^/]+
:
Options +FollowSymLinks -Indexes
<Files .htaccess>
deny from all
</Files>
RewriteEngine On
# skip files and directories from further rules:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ index.php?c=$1 [QSA,L]
RewriteRule ^([^/]+)/filtre/([^/]+)/?$ index.php?c=$1&av=$2 [NC,L,QSA]
RewriteRule ^([^/]+)/water/brand-([^/]+)/country-([^/]+)/filter/(.*)/?$ index.php?c=$1&brand=$2&country=$3&av=$4 [NC,L,QSA]
Options+FollowSymLinks-索引
全盘否定
重新启动发动机
#从其他规则中跳过文件和目录:
RewriteCond%{REQUEST_FILENAME}-d[或]
RewriteCond%{REQUEST_FILENAME}-f
重写规则^-[L]
重写规则^([^/]+)/?$index.php?c=$1[QSA,L]
重写规则^([^/]+)/filter/([^/]+)/?$index.php?c=$1&av=$2[NC,L,QSA]
重写规则^([^/]+)/water/brand-([^/]+)/country-([^/]+)/filter/(.*)/?$index.php?c=$1&brand=$2&country=$3&av=$4[NC,L,QSA]
这仅适用于av过滤器,但如果我添加到url&brand=$val&country=$val?无法理解您的评论。您在浏览器中输入的URL是什么?您希望内部重写的URI是什么?我的URL可能类似:http://localhost/index.php?c=water&brand=dorna&country=romania&av=1L|重量,矿物|类型
我的问题还有第二部分。您想要什么作为http://localhost/index.php?c=water&brand=dorna&country=romania&av=1L|重量,分钟一般类型
?当前url:http://localhost/index.php?c=water&brand=dorna&country=romania&av=1L|重量,分钟eral |键入
,重写后的我的url应该是:http://localhost/water/brand-dorna/country-romania/filter/1L|重量,矿物类型