Reputation: 943
I've a problem to rewrite url in my site with .htaccess
index.php
$op = $_GET['op'];
switch ($op) {
case "src":
include("src.php");
break;
case "dts":
include ("dts.php");
break;
default:
include("home.php");
break;
}
Link to rewrite
index.php?op=src
index.php?op=dts&idric=20&sp=2
.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]
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).
Upvotes: 0
Views: 105
Reputation: 784898
RewriteCond
is only applier to very next RewriteRule
. And your last rule gets overridden by previous one.
Have your rules like this:
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]
Upvotes: 2