Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于.htaccess的问题_.htaccess_Mod Rewrite - Fatal编程技术网

关于.htaccess的问题

关于.htaccess的问题,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我拥有in.htaccess: RewriteRule ^index.php cont.php?id=1 但是如果我浏览index.php?image=bla.jpg 出于某种原因,我看到了这个页面:cont.php?id=1 我该如何做?只有url index.php会打开cont.php?id=1,而不是像index.php?image=bla.jpg这样的其他url ? 谢谢 RewriteRule ^index.php cont.php?id=1 [QSA] 您需要QSA属性—它告

我拥有in.htaccess:

RewriteRule ^index.php cont.php?id=1
但是如果我浏览index.php?image=bla.jpg

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

我该如何做?只有url index.php会打开cont.php?id=1,而不是像index.php?image=bla.jpg这样的其他url

?

谢谢

 RewriteRule ^index.php cont.php?id=1 [QSA]
您需要QSA属性—它告诉Apache将任何查询字符串传递到重写的地址

RewriteRule ^index.php$ cont.php?id=1
您需要QSA属性—它告诉Apache将任何查询字符串传递到重写的地址

RewriteRule ^index.php$ cont.php?id=1
在index.php之后添加多勒符号

RewriteRule ^index.php cont.php?id=1
在index.php之后添加多勒符号

RewriteRule ^index.php cont.php?id=1
它匹配从index.php开始的所有内容,^就是这个意思。您需要说路径也必须以$sign结尾

逃离危险。也是可建议的,否则它将匹配任何单个字符,例如index1php

它匹配从index.php开始的所有内容,^就是这个意思。您需要说路径也必须以$sign结尾


逃离危险。也是可建议的,否则它将匹配任何单个字符,例如index1php。

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

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

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

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

要提到的两件重要事情是1转义“.”字符2在RewriteRule 3[QSA]不起作用之前使用RewriteCond属性,因为这意味着只在末尾追加查询字符串。就你的情况而言,QSA不是合适的。在回答这个问题时,有两件重要的事情需要提及:1.转义“.”字符2.在RewriteRule 3[QSA]不起作用之前使用RewriteCond属性,因为这意味着只在末尾追加查询字符串。就你的情况而言,QSA不是合适的。同意这个答案