.htaccess URL重写挑战

.htaccess URL重写挑战,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我的URL重写有问题 下面的所有内容都很好,但我需要添加一个规则,从URL中删除查询字符串 site.com/page?a=b 将成为 site.com/page 有人能帮忙吗?我读了一些关于.htaccess的书,但我发现它非常复杂。此外,还需要知道我的新指令应该出现在文件中的什么位置 谢谢 # EE 404 page for missing pages ErrorDocument 404 /index.php/404/index # Simple 404 for missi

我的URL重写有问题

下面的所有内容都很好,但我需要添加一个规则,从URL中删除查询字符串

site.com/page?a=b 将成为 site.com/page

有人能帮忙吗?我读了一些关于.htaccess的书,但我发现它非常复杂。此外,还需要知道我的新指令应该出现在文件中的什么位置

谢谢

# EE 404 page for missing pages ErrorDocument 404 /index.php/404/index # Simple 404 for missing files ErrorDocument 404 "File Not Found" # Rewriting will likely already be on, uncomment if it isnt RewriteEngine On RewriteBase / # Block access to "hidden" directories whose names begin with a period. This # includes directories used by version control systems such as Subversion or Git. RewriteRule "(^|/)\." - [F] # remove the www - Uncomment to activate # # RewriteCond %{HTTPS} !=on # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] # RewriteRule ^(.*)$ http://%1/$1 [R=301,L] # # Remove the trailing slash to paths without an extension # Uncomment to activate # # RewriteRule ^(.*)/$ /$1 [R=301,L] # # Remove index.php # Uses the "include method" # http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method # RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC] RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/(home|inc|publishers|sidebars|about|include-template|testing|advertisers|products|sitemap|style|ad-choices|social-bar|search|404||members|P[0-9]{2,8}) [NC] RewriteRule (.*) /index.php/$1 [L] #EE 404缺失页面的页面 ErrorDocument 404/index.php/404/index #简单404查找丢失的文件 错误文档404“未找到文件” #重写可能已经打开,如果没有,则取消注释 重新启动发动机 重写基/ #阻止访问名称以句点开头的“隐藏”目录。这 #包括版本控制系统(如Subversion或Git)使用的目录。 重写规则“(^ |/)\”-[F] #删除www-Uncomment以激活 # #重写cond%{HTTPS}=在…上 #重写cond%{HTTP_HOST}^www\.(.+)$[NC] #重写规则^(.*)$http://%1/$1[R=301,L] # #删除不带扩展名的路径的尾部斜杠 #取消注释以激活 # #重写规则^(.*)/$/$1[R=301,L] # #删除index.php #使用“包含方法” # http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method # 重写cond%{QUERY_STRING}^(ACT=.*)$[NC] 重写cond%{REQUEST_URI}!(\[a-zA-Z0-9]{1,5})$ 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D RewriteCond%{REQUEST|URI}^/(home | inc | publisher | sidebars | about | include template | testing |广告商| products | sitemap | style |广告选择| social bar | search | 404 404会员| P[0-9]{2,8})[NC] 重写规则(.*)/index.php/$1[L]
这将从url中删除查询字符串

RewriteRule ^(.*) /index.php/$1? [L] #remove query string

希望它能有所帮助

我的回答有点晚了,但是因为我正在搜索类似的行为,我想我应该分享一下:你也可以在重写规则中添加一个标志来删除查询字符串;标志是
[QSD]
,它有助于避免像结尾处的
这样的变通方法;-)


您可以找到有关此标志的更多信息。我想指出,“此标志在[Apache]2.4.0版及更高版本中可用”

只需在上一条规则中的
$1
之后添加一个
<代码>重写规则(.*)/index.php/$1?[五十]