如何从带有查询字符串的 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/