htaccess的URL重写multple网址 [英] htaccess url rewrite multple url

查看:129
本文介绍了htaccess的URL重写multple网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,用的.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]

这篇关于htaccess的URL重写multple网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆