Apache 使用htaccess重写url

Apache 使用htaccess重写url,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,如何使用htaccess以这种方式更改url: 某物.php 应重定向到: 某物 如果get参数名称与'go'不同,请保持原样…类似的内容(通过谷歌查找正确的语法) 这应该做到: # Assuming that "RewriteEngine On" has already been called RewriteCond %{QUERY_STRING} ^(.*&)?go=([a-z]+)\.php(&.*)?$ RewriteRule page.php %2? 这里发生了什么?

如何使用htaccess以这种方式更改url:

某物.php

应重定向到:

某物

如果get参数名称与'go'不同,请保持原样…

类似的内容(通过谷歌查找正确的语法)

这应该做到:

# Assuming that "RewriteEngine On" has already been called
RewriteCond %{QUERY_STRING} ^(.*&)?go=([a-z]+)\.php(&.*)?$
RewriteRule page.php %2?
这里发生了什么?首先,RewriteCond匹配一个查询字符串,该字符串包含
go=something.php
,其中“something”由
([a-z]+)
捕获。然后,RewriteRule使用RewriteCond中的第二个捕获组的内容,其中包含“something.php”。末尾的问号去掉了原始查询字符串

注意:如果您想保留查询字符串的其余部分(不包括
go=…
参数),那么事情会变得有点复杂


有关更多信息,请参阅中的文档。

使用此功能的缺点是,
page.php?something&go=login.php
不起作用,在
page.php?go=login.phpjunk
google上仍然可以找到正确的语法以及如何解决这些问题。e、 g.在login.php之后添加$login,以防止触发login.phpjunk
# Assuming that "RewriteEngine On" has already been called
RewriteCond %{QUERY_STRING} ^(.*&)?go=([a-z]+)\.php(&.*)?$
RewriteRule page.php %2?