我有以下。htaccess文件代码
RewriteEngine On
RewriteBase /claimspro/
##-----Establish a custome 404 File not Found Page---
ErrorDocument 404 /claimspro/filenotfound.php
##-----Prevent Directory File listing in all folder---
IndexIgnore *
RewriteCond %{THE_REQUEST} ([A-Za-z0-9]+).php?caseid=([0-9]+)&?([^ ]*)
RewriteRule ^ %1/caseid/%2/?%3 [L,R]
RewriteRule ^([A-Za-z0-9]+)/caseid/([0-9]+)/ $1.php?caseid=$2 [L,QSA]
RewriteCond %{THE_REQUEST} ([A-Za-z0-9]+).php
RewriteRule ^ %1/?%2 [L,R]
RewriteRule ^([A-Za-z0-9]+)/ $1.php [L,QSA]
上面的代码按照我想要的方式工作。它会将url从localhost/claimspro/afile.php?caseid=11
变为localhost/claimspro/afile/caseid/11/
但是当我通过以下方式添加另一个参数,即/caseid/11/picid/12/时,它的行为很奇怪。
我可以要求一些代码的解释,所以可以设法得到一些对我有利的结果。
RewriteCond %{THE_REQUEST} ([A-Za-z0-9]+).php?caseid=([0-9]+)&?([^ ]*)
RewriteRule ^ %1/caseid/%2/?%3 [L,R]
首先,如果我可以问这是什么在第一行的末尾(上面)&?([^ ]*)
我如何修改它来添加另一个参数,如RewriteCond %{THE_REQUEST} ([A-Za-z0-9]+).php?caseid=([0-9]+)&picid=([0-9]+)&?([^ ]*)
。如果你能解释一下我在这里做错了什么,我该怎么做呢?
第二行RewriteRule ^ %1/caseid/%2/?%3 [L,R]
?%3 [L,R]
%3代表什么?
基本上,我想在我的htaccess文件中添加一个参数,以满足以下
localhost/claimspro/anotherfile.php?caseid=11&picid=22
我应该在我的代码中添加什么?
任何想法?
让我来回答你的两个问题。
回答第一个问题:模式&?([^ ]*)
匹配查询字符串的其余部分(如果存在)。
第二个问题的答案:?%3 [L,R]
将捕获的数据(从第一个问题)附加为查询字符串(R
标志默认情况下用于使用302重定向)。
如果我必须这样做,我会这样写
Options -Indexes
ErrorDocument 404 /claimspro/filenotfound.php
RewriteEngine On
RewriteBase /claimspro/
RewriteCond %{THE_REQUEST} /([^/]+).php?caseid=([0-9]+)&picid=([0-9]+)s [NC]
RewriteRule . %1/caseid/%2/picid/%3/? [R=301,L]
RewriteCond %{THE_REQUEST} /([^/]+).php?caseid=([0-9]+)s [NC]
RewriteRule . %1/caseid/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} /([^/]+).phps [NC]
RewriteRule . %1/? [R=301,L]
RewriteRule ^([^/]+)/caseid/([0-9]+)/picid/([0-9]+)/$ $1.php?caseid=$2&picid=$3 [L]
RewriteRule ^([^/]+)/caseid/([0-9]+)/$ $1.php?caseid=$2 [L]
RewriteRule ^([^/]+)/$ $1.php [L]
我不能解释代码,因为我不是模式重写的专家,你可以用下面的代码改变你的代码,它会工作
RewriteEngine On
RewriteBase /claimspro/
#-----Establish a custome 404 File not Found Page---
ErrorDocument 404 /claimspro/filenotfound.php
#-----Prevent Directory File listing in all folder---
IndexIgnore *
RewriteCond %{THE_REQUEST} ([A-Za-z0-9]+).php?caseid=([0-9]+)&picid=([0-9]+)&?([^ ]*)
RewriteRule ^ %1/caseid/%2/picid/%3/?%4 [L,R]
RewriteRule ^([A-Za-z0-9]+)/caseid/([0-9]+)/picid/([0-9]+)/ $1.php?caseid=$2&picid=$3 [L,QSA]
RewriteCond %{THE_REQUEST} ([A-Za-z0-9]+).php
RewriteRule ^ %1/?%2 [L,R]
RewriteRule ^([A-Za-z0-9]+)/ $1.php [L,QSA]
让我知道它是否有效
对