简体   繁体   English

.htaccess从index.php重定向不起作用

[英].htaccess redirect from index.php not working

I did my best to search in stack overflow questions and answers and even when I tried to apply a solution, it is not working. 我尽力搜索堆栈溢出问题和答案,即使尝试应用解决方案,它也无法正常工作。

I need to redirect all adresses, that begin with 我需要重定向所有以

http://www.example.com/index.php?lang=XX http://www.example.com/index.php?lang=XX

to

http://www.example.com/XX http://www.example.com/XX

This is what I try: 这是我尝试的方法:

RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
RewriteRule ^(index\.php\?lang\=)$ http://www.example.com/$1 [L,R=302]

The location /index.php?lang=en is not redirecting /en (anywhere). 位置/index.php?lang=en 不会重定向/ en(任何位置)。 It is at the same URL. 它在相同的URL。

You can't match a query_string in a rewriterule. 您无法在重写器中匹配query_string。 You need a specific RewriteCond for it. 您需要一个特定的RewriteCond。 It should be more or less like this: 应该或多或少像这样:

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{QUERY_STRING} ^lang=(.*)
RewriteRule ^ http://www.example.com/%1 [R=302,L,QSD]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM