使用 .htaccess 从 URL 中删除查询字符串
Remove query string from URL using .htaccess
我正在尝试使用 .htaccess 进行以下重定向。
重定向:
http://www.example.com/index.php?something@gmail.com
为此:
http://www.example.com/index.php?something
所以基本上我想要的只是在保留所有其他内容的同时从查询字符串中删除 @gmail.com
。
我尝试了以下方法:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)@gmail.com$
RewriteRule (.*) ?%1%2? [R=permanent]
不幸的是,即使在进行了多次调整之后也没有奏效。怎么了?
根据您显示的 samples/attempts,请尝试以下操作。请确保在测试您的 URL 之前清除您的浏览器缓存。请确保 htacces 和 index.php 文件位于同一级别的根文件夹中。
RewriteEngine ON
##Redirect rules to get index.php?something in browser here.
RewriteCond %{THE_REQUEST} \s/(index\.php)\?([^@]*)@.*\s [NC]
RewriteRule ^ /%1?%2 [R=301,L]
我正在尝试使用 .htaccess 进行以下重定向。
重定向:
http://www.example.com/index.php?something@gmail.com
为此:
http://www.example.com/index.php?something
所以基本上我想要的只是在保留所有其他内容的同时从查询字符串中删除 @gmail.com
。
我尝试了以下方法:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)@gmail.com$
RewriteRule (.*) ?%1%2? [R=permanent]
不幸的是,即使在进行了多次调整之后也没有奏效。怎么了?
根据您显示的 samples/attempts,请尝试以下操作。请确保在测试您的 URL 之前清除您的浏览器缓存。请确保 htacces 和 index.php 文件位于同一级别的根文件夹中。
RewriteEngine ON
##Redirect rules to get index.php?something in browser here.
RewriteCond %{THE_REQUEST} \s/(index\.php)\?([^@]*)@.*\s [NC]
RewriteRule ^ /%1?%2 [R=301,L]