我有这样的网址
http://be.ac/index.php?category=all&providers=all&keyword=cookies&page=1
我想像这样重写:
http://be.ac/category/all/providers/all/keyword:cookies/page:1
这是我的htaccess
RewriteEngine on
RewriteRule ^page:([^/]*)/?$ index.php?page=$1 [QSA,L]
RewriteRule ^category/([^/]*)/?$ index.php?category=$1 [QSA,L]
RewriteRule ^category/([^/]*)/page:([^/]*)/? index.php?category=$1&page=$2 [QSA,L]
RewriteRule ^category/([^/]*)/providers/([^/]*)/page:([^/]*)? index.php?category=$1&providers=$2&page=$3 [QSA,L]
RewriteRule ^category/([^/]*)/providers/([^/]*)/keyword:([^/]*)/page:([^/]*)? index.php?category=$1&providers=$2&keyword=$3&page=$4 [QSA,L]
这不起作用,我需要的是接受这样的网址:
http://be.ac/category/all/providers/all/keyword:cookies/page:1
http://be.ac/category/all/providers/all/page:1
http://be.ac/category/all/page:1
http://be.ac/page:1
http://be.ac/keyword:cookies
任何想法?
答案 0 :(得分:0)
我认为这个问题与冒号有关。首先猜测是需要对它们进行编码,除非是在散列字符串中。
因此,您将收到 403 Forbidden 错误 - 但是,您未在问题中指明。
我唯一可以推荐的是将正斜杠的冒号切换出来,这样可以保持URI的一致性(就像你使用category/<something>
代替category:<something>
一样):
RewriteEngine on
RewriteRule ^page/([^/]+)/?$ index.php?page=$1 [QSA,L]
RewriteRule ^category/([^/]+)/?$ index.php?category=$1 [QSA,L]
RewriteRule ^category/([^/]+)/page/([^/]+)/? index.php?category=$1&page=$2 [QSA,L]
RewriteRule ^category/([^/]+)/providers/([^/]+)/page/([^/]+)/?$ index.php?category=$1&providers=$2&page=$3 [QSA,L]
RewriteRule ^category/([^/]+)/providers/([^/]+)/keyword/([^/]+)/page/([^/]+)/?$ index.php?category=$1&providers=$2&keyword=$3&page=$4 [QSA,L]
此外,我已将([^/]*)
更改为([^/]+)
,并修复了最后两个问题的尾随斜杠问题(它们与其他问题不一致)。