关于.htaccess的问题

时间:2011-06-13 08:46:31

标签: .htaccess mod-rewrite

我有.htaccess:

RewriteRule ^index.php cont.php?id=1

但如果我冲浪到 index.php?image = bla.jpg

出于某种原因,我看到了页面: cont.php?id = 1

我怎样才能做到唯一的网址 index.php 会打开 cont.php?id = 1 而不是 index.php?image = bla .JPG

感谢。

4 个答案:

答案 0 :(得分:2)

RewriteRule ^index.php cont.php?id=1

匹配开始index.php的所有内容(这就是^的含义)。您需要说明路径必须结束,这由$符号表示。 (Apache docs

RewriteRule ^index\.php$ cont.php?id=1

也建议转义.,否则它会匹配任何单个字符(例如index1php)。

答案 1 :(得分:2)

您还需要检查请求的URI查询:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ cont.php?id=1

答案 2 :(得分:1)

RewriteRule ^index.php$ cont.php?id=1

在index.php之后添加美元符号

答案 3 :(得分:0)

 RewriteRule ^index.php cont.php?id=1 [QSA]

你需要QSA属性 - 它告诉Apache将任何查询字符串传递给重写的地址

相关问题