从Rootdomain删除查询字符串字符串、Rootdomain

由网友(浪花一朵朵)分享简介:我知道,有一个简单的重定向一(子)域或文件夹到另一个我可以摆脱一个字符串,像这样I know with a simple redirect one (Sub-)Domain or Folder to another i can get rid of a string like thisRewriteEngine O...

我知道,有一个简单的重定向一(子)域或文件夹到另一个我可以摆脱一个字符串,像这样

I know with a simple redirect one (Sub-)Domain or Folder to another i can get rid of a string like this

RewriteEngine On
RewriteRule (.*) http://www.domain.tld/? [R=301,L]

我知道如何摆脱它时,它是一个简单的文件了。

I know how to get rid of it when it is a simple file too.

但是,当涉及到Rootdomain本身( HTTP://domain.tld/ Stringwhatsoever )我在这里的损失。我最后一次尝试使用重定向我用重定向各地文件和文件夹的修改版本和工作pretty的很好,也去掉了查询,但它在一个重定向错误结束了。

But when it comes to the Rootdomain itself (http://domain.tld/?Stringwhatsoever), i am at a loss here. My last try used a modified version of a redirect I used to redirect files and folders around and that worked pretty nicely and also removed the query, but it ended up in a redirection error.

RewriteRule ^ http://domain.tld/? [L,NC,R=301]

所以,我不知道如何在网址摆脱查询字符串不破坏它。

So i have no clue how to get rid of Query Strings at urls without breaking it.

推荐答案

试试这个:

RewriteEngine On
RewriteCond %{THE_REQUEST} /?([^s]+) [NC] 
RewriteRule ^$ http://domain.com/? [NC,R,L]

RewriteEngine On
RewriteCond %{QUERY_STRING} (.+) [NC] 
RewriteRule ^$ http://domain.com/? [NC,R,L]

参考:

- https://wiki.apache.org/httpd/RewriteQueryString

阅读全文

相关推荐

最新文章