Forum Moderators: phranque

Message Too Old, No Replies

Modrewrite several querys

         

define

10:38 am on Sep 13, 2007 (gmt 0)

10+ Year Member



I need help

i want to rewrite
http://www.example.com/index.php?akcija=vesti&do=izlistaj&kat=music&podkatid=rock
to
www.example.com/music/rock/

and

www.example.com/index.php?akcija=kategorija&kat=music
to
www.example.com/music/

when i do this

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_string} (.*)
RewriteRule ^([^.]*)/$ index.php?akcija=kategorija&kat=$1&%1[L]
RewriteRule ^([^.]*)/$ index.php?akcija=kategorija&kat=$1[L]

this works www.example.com/music/

but when i add

RewriteRule ^([^.]*)/$ index.php?akcija=vesti&do=izlistaj&kat=$1&podkatid=$2&%1[L]
RewriteRule ^([^.]*)/$ index.php?akcija=vesti&do=izlistaj&kat=$1&podkatid=$2[L]

it don't work, can you help me, i tryed several posts but no result

[edited by: jdMorgan at 2:25 pm (utc) on Sep. 13, 2007]
[edit reason] example.com [/edit]

jdMorgan

2:46 pm on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure how you intend to derive the four query string variables in the case where only one "subdirectory" is given in the static URL. But a point solution might be:

RewriteRule ^([^/.]+)/?$ /index.php?akcija=vesti&do=izlistaj&kat=$1&podkatid=rock [L]
RewriteRule ^([^/]+)/([^/.]+)/?$ /index.php?akcija=vesti&do=izlistaj&kat=$1&podkatid=$2 [L]

You can continue this sequence to extract the other parameters if needed.

Jim

define

3:20 pm on Sep 13, 2007 (gmt 0)

10+ Year Member



not woking

i have this

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_string} (.*)
RewriteRule ^([^.]*)/$ index.php?akcija=kategorija&kat=$1&%1[L]
RewriteRule ^([^.]*)/$ index.php?akcija=kategorija&kat=$1[L]

RewriteRule ^([^/]+)/([^/.]+)/?$ /index.php?akcija=vesti&do=izlistaj&kat=$1&podkatid=$2 [L]

------------------
when i try this
www.example.com/music/ ->this works

www.example.com/music/rock/ ->not working

it is opening index.php?akcija=vesti&do=izlistaj&kat=$1&podkatid=$2
but when i print kat i get "index.php" insted of "music"

jdMorgan

10:46 pm on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The patterns in your first two rules are too ambiguous. Remember that ".*" matches anything and everything.

The third rule will never be invoked.

Comment-out the first two rules, and test the third rule. It should work.

And please notice that I posted one rule that will replace the first two current rules above. It is not necessary to "copy" the query string manually as you have done in your first rule; If you do not change the query string, it will pass through mod_rewrite unmodified.

Jim

define

9:08 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



It is working now, thanks

I have one problem
i have folder admin and when i try to access www.example.com/admin/ apache is thinking admin is value, is there chance to tell apache not to consider my folder admin

jdMorgan

10:46 pm on Sep 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just add a RewriteCond to the rule:

RewriteCond %{REQUEST_URI} !^/admin/

Jim