我在重写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]
答案 0 :(得分:8)
这会从网址中删除查询字符串
RewriteRule ^(.*) /index.php/$1? [L] #remove query string
希望有所帮助
答案 1 :(得分:2)
我的答案有点迟了,但由于我正在寻找类似的行为,我认为我应该分享它:你还可以在重写规则中添加一个标志来删除查询字符串;标志为[QSD]
,它有助于避免最后?
之类的变通办法; - )
Here您可以找到有关此标志的更多信息。我想指出“这个标志在[Apache] 2.4.0及更高版本中可用”