WatsMyName WatsMyName - 24 days ago 9
Apache Configuration Question

URL rewriting to a folder if url has one pattern and ignore the rule if url has another pattern

I have following directory structure for the project

example
admin/
cdn/
client/
.htaccess


When the url is


  • http://192.168.1.121/example/
    or

  • http://192.168.1.121/example
    or

  • http://192.168.1.121/example/category/productname
    or

  • http://192.168.1.121/example/content/12
    and so on,



it should rewrite to
client/
folder.

But if url has
http://192.168.1.121/example/cdn
, it should ignore the rule.

Can anybody help me on this. How to write the rule in
.htaccess


Thanks

Answer

You can use this /example/.htaccess:

RewriteEngine On
RewriteBase /example/

RewriteRule ^(?!client/|cdn)(.*)$ client/$1 [L,NC]

(?!client/|cdn) is negative lookahead to ignore the rule when URI is /example/cdn OR /example/client

Comments