我想将所有以 www.site.com/online/ 开头的 URL 重定向到 www.site.com
我尝试重定向的一些文件示例是......
www.site.com/online/folder1/folder2/folder3/?gdt=wbgMfFt9PVUKEwjiparBqM-kAhUMdoYKHW5GKa0QAhgBIAQw-PuCATgeUPj7ggFQpPmYD1CGra8PUIvr_xNQuOv_E1DU6IQbUIq23B5QsuXZIFD5uqqnAVCDrYrIAVCgy5HZAQ&slt=8&slr=5&lpt=2
我当前的情况非常简单,除了删除 url 中的参数之外,它正在执行所有操作。
RewriteRule ^online/(.*) http://www.site.com [R=301,L]
现在此规则将重定向
www.site.com/online/folder1/folder2/folder3/?randomgetparameter=blablabla
到
www.site.com/?randomgetparameter=blablabla
而不是重定向到
www.site.com
答案1
Modifying the Query String
By default, the query string is passed through unchanged. You can, however,
create URLs in the substitution string containing a query string part.
Simply use a question mark inside the substitution string to indicate that
the following text should be re-injected into the query string. When you want
to erase an existing query string, end the substitution string with just a
question mark. To combine new and old query strings, use the [QSA] flag.
因此——尝试:RewriteRule ^online/(.*) http://www.site.com/?[右=301,左]