.htaccess - htaccess 仅从带有查询字符串的 URL 中删除 '?' 符号

标签 .htaccess query-string ssi

如何从带有查询字符串的 URL 中删除 ? 符号

最佳答案

RewriteEngine On

# This is to physically change what's in the browser's address bar using a client redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?([^\ ]+)
RewriteRule ^$ /%1? [R=301,L]

# This is to internally rewrite on the server side
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?(.+)$ /?$1 [L]

Also please could you explain me what does mean [A-Z]{3,9}\ and ([^\ ]+) on its own? Where I can read about building this type of structures?

该正则表达式用于匹配 HTTP 请求,第一行将如下所示:

GET /path/to/file HTTP/1.1

第一个单词是 METHOD,长度可以是 3 到 9 个字符之间的任意位置(因此是 {3,9},第二个单词是 unaltered 请求的 URI。这是经过重写引擎的,但在对其进行任何路径处理之前。最后一位是协议(protocol)版本,在某种程度上是可选的,并确定之后是否会有 header .

关于.htaccess - htaccess 仅从带有查询字符串的 URL 中删除 '?' 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11874142/

相关文章:

php - 无法使用 HTACCESS 创建漂亮的 url

Django/HTTP - 使用 POST 请求发送查询字符串 - 不推荐吗?

amazon-web-services - 使用服务器端include或ssi,AWS S3

cordova - PhoneGap 应用程序服务器端包含 (SSI)

url - 使用SSI获取URL和参数

angularjs - "base href"使用 ui-router 在路由 url 中添加目录路径

apache - .htaccess 文件在带有 apache2 的 Ubuntu 14.04 上不起作用

.htaccess - 301重定向获取分页

javascript - 如何使用 jQuery 将查询字符串传递给 Ajax 调用?

.net - 如何使查询字符串防篡改?