我想要使用.htaccess的带有查询字符串的SEO友好网址,并在php $ _GET变量中获取值
http://localhost/blog/categoryslug/postslug/?rf=1234&key=ad2312
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+?)/?$ /blog/detail.php?cat_slug=$1&slug=$2 [L]
但是在print_r上,我只有2个键:
print_r($_GET); exit;
Array
(
[cat_slug] => categoryslug
[slug] => postslug
)
同时,我需要像这样的查询字符串中的所有键和值:
Array
(
[cat_slug] => categoryslug
[slug] => postslug
[rf] => 1234
[key] => ad2312
)
请帮助我解决这个问题
TIA
答案 0 :(得分:1)
尝试以下操作,我添加了QSA
标志,将原始传入查询附加到您的请求中。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+?)/?$ /blog/detail.php?cat_slug=$1&slug=$2 [L,QSA]
答案 1 :(得分:0)
尝试以下代码:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+?)\?(.*)/?$ /blog/detail.php?cat_slug=$1&slug=$2&$3 [L]