带查询的 mod 重写 [英] mod rewrite with query
问题描述
可能的重复:
查询字符串&Mod重写
我正在尝试使用 mod rewrite 使没有 www 的链接更漂亮,然后从:http://example.com/folder/page.html
到http://example.com/index.php?page=page&folder=folder
I'm attempting to use mod rewrite to make links prettier without www and go from:
http://example.com/folder/page.html
to
http://example.com/index.php?page=page&folder=folder
我已经为不在文件夹中的顶层页面管理了一个基本版本,但我很困惑如何包含此规则并让文件夹出现.我还希望保留查询字符串,以便 piwik 分析链接正常工作,例如:http://example.com/folder/page.html?piwik=something
转到:http://example.com/index.php?page=page&folder=folder&piwik=something
I've managed a basic version of this for top layer pages which are not in folders but am puzzeled how to include this rule and get folder to appear. I would also like query strings to stay so piwik analytic links work, such as:
http://example.com/folder/page.html?piwik=something
goes to:
http://example.com/index.php?page=page&folder=folder&piwik=something
任何帮助将不胜感激,这是我目前所得到的:
Any help would be most appreciated, this is what I've got so far:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^([^/]*)\.html$ /index.php?page=$1 [L]
</IfModule>
推荐答案
您想要 QSA
标志Docs,示例代码如下:
You want the QSA
flagDocs, example code below:
RewriteRule ^/([^/]+/)?(.+\.html)$ /index.php?folder=$1&page=$2 [QSA,L]
参考:找到这个页面 http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html只需按 CTRL+F 并搜索QSA"(无语音标记)
Reference: Found this page http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html Just hit CTRL+F and search for "QSA" (without speech marks)
这篇关于带查询的 mod 重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!