【发布时间】:2012-02-14 17:47:39
【问题描述】:
我在某些 URL 重写方面遇到了问题。
下面的所有东西都可以正常工作,但我需要添加一个从 URLS 中删除查询字符串的规则。
site.com/page?a=b 会变成 site.com/page
有人可以帮忙吗?我在 .htaccess 上做了一些阅读,但我发现它非常复杂。另外,需要知道我的新指令应该出现在文件中的哪个位置。
谢谢。
# 缺少页面的 EE 404 页面 错误文档 404 /index.php/404/index # 丢失文件的简单 404 ErrorDocument 404“找不到文件” # 重写可能已经开启,如果没有,请取消注释 重写引擎开启 RewriteBase / # 阻止访问名称以句点开头的“隐藏”目录。这 # 包括版本控制系统使用的目录,例如 Subversion 或 Git。 重写规则 "(^|/)\." - [F] # 去掉 www - 取消注释激活 # # RewriteCond %{HTTPS} !=on # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] # RewriteRule ^(.*)$ http://%1/$1 [R=301,L] # # 删除没有扩展名的路径的尾部斜杠 #取消注释激活 # # 重写规则 ^(.*)/$ /$1 [R=301,L] # # 删除 index.php # 使用“包含方法” # 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] 重写规则 (.*) /index.php/$1 [L]【问题讨论】:
-
只需在最后一条规则中的
$1之后添加一个?。RewriteRule (.*) /index.php/$1? [L]
标签: .htaccess mod-rewrite