.htaccess的查询字符串重写 [英] Htaccess Querystring rewrite

查看:273
本文介绍了.htaccess的查询字符串重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网址 /?测试,我想重写 /page.php?page=test

I have URLs like /?test that I want to rewrite to /page.php?page=test

我想这样的,但由于某种原因,这是行不通的。

I tried like this but for some reason it doesn't work.

RewriteRule ^\?([a-z0-9\-\+]{3,20})/?$ /page.php?page=$1 [NC,QSA]

我是什么做错了吗?

What am I doing wrong?

推荐答案

查询字符串只能用的 的RewriteCond 指令。该 重写规则 模式仅针对 URL路径(在.htaccess文件,而每个目录preFIX的URL路径)。

The query string can only be tested with the RewriteCond directive. The RewriteRule pattern is only tested against the URL path (in .htaccess files the URL path without the per-directory prefix).

那么试试这个:

RewriteCond %{QUERY_STRING} ^[a-z0-9-+]{3,20}$ [NC]
RewriteRule ^$ /page.php?page=%0 [QSA]

这篇关于.htaccess的查询字符串重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆