作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要逃避“?” url 中的字符,以便它与重写的 url 一起使用,例如 search/why-is-it?-1.html
我目前在 .htaccess 中有以下内容
RewriteEngine on
RewriteRule ^search/(.*)-([0-9]+).html$ index.php?search=$1&page=$2 [L]
最佳答案
不要在您的网址中添加问号。 ?
保留用于查询字符串的开头。
要将其放在 URL 中,请将其编码为 %3F
.
阅读 RFC和 this answer .
更新
如果使用 PHP(看起来你是),你可以做这样的事情(请求的页面是 index.php/inter?net
)...
<?php
var_dump($_GET);
$urlTokens = explode('/', $_SERVER['REQUEST_URI']);
$slug = end($urlTokens);
var_dump($slug);
array(1) {
["net"]=>
string(0) ""
}
string(9) "inter?net"
$_GET
很困惑。
关于regex - 如何在 .htaccess 中使用正则表达式转义 "?"for mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5161967/
我是一名优秀的程序员,十分优秀!