我有一个问题,用的.htaccess重写URL在我的网站
I've a problem to rewrite url in my site with .htaccess
的index.php
index.php
$op = $_GET['op'];
switch ($op) {
case "src":
include("src.php");
break;
case "dts":
include ("dts.php");
break;
default:
include("home.php");
break;
}
链接重写
index.php?op=src
index.php?op=dts&idric=20&sp=2
的.htaccess
.htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule .(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ index.php?op=$1 [L,QSA]
RewriteRule ^(.*)/idric/(.*)/sp/(.*)/$ index.php?op=$1&idric=$2&sp=$3 [L,QSA]
如果我写的第一个环节www.mysite.com/src/它显示正确的页面(src.php) 但如果我写的第二个URL www.mysite.com/dts/idric/20/sp/2/它显示的默认页面(home.php)。
If I write the first link www.mysite.com/src/ it shows the correct page (src.php), but if I write the second url www.mysite.com/dts/idric/20/sp/2/ it shows the default page (home.php).
有人可以告诉我怎么解决? 谢谢
Can someone tell me how to solve? Thank you
的RewriteCond
只施放到第二天重写规则
。而你的最后一条规则得到由previous 1所覆盖。
RewriteCond
is only applier to very next RewriteRule
. And your last rule gets overridden by previous one.
让你的规则是这样的:
Options +FollowSymLinks
RewriteEngine on
RewriteRule .(css|jpe?g|gif|png|js|ico)$ - [L,NC]
# rule to ignore files and directories from all rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/idric/([^/]+)/sp/([^/]+)/$ index.php?op=$1&idric=$2&sp=$3 [L,QSA,NC]
RewriteRule ^(.+?)/$ index.php?op=$1 [L,QSA]