0

all. I search the sites but can not find my answer, so I post it.

I want to redirect url like this

example.com/css/.... ====> example.com/templates/css/...

example.com/path/css/.... ====> example.com/path/templates/css/...

I tired lots regular, not I wish. such as

RedirectMatch (.*)/css/(.*)\.css  $1/templates/css/$2.css 

I think the last regular maybe right. but need set regular to lazy-mode. I find the apache document about mod_alias and mod_rewrite, haven't found talk about this tips.

need help. thanks !

9nix00
  • 3,852
  • 2
  • 21
  • 27

2 Answers2

0

You get lazy match by adding ? after *, like this:

(.*?)/css/(.*?)\.css

The * then tries to match as little as possible. This should transform the urls in your example as you expect.

By the way: Apache mod_rewrite is Perl compatible regular expression with some additions.

Staffan Nöteberg
  • 4,095
  • 1
  • 19
  • 17
  • this regular is right. but will cause loops for this url css ==> templates/css . I am thinking it. – 9nix00 Apr 11 '11 at 04:25
0

ok,I check it out , and I leaned reglar assert features XD.

(^(t(?!emplates)|[^t])*?)/(css|js)/(.*)\.(css|js)$ $1/templates/$3/$4.$5

this works very well for me . hope can help some people.

9nix00
  • 3,852
  • 2
  • 21
  • 27