本文介绍了htaccess网址重写多个网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用.htaccess重写网站中的网址时遇到问题
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).
推荐答案
RewriteCond
仅适用于下一个 RewriteRule
。您的最后一条规则将被上一条覆盖。
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]
这篇关于htaccess网址重写多个网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!