简体   繁体   中英

Apache2: redirect based on URL

I'm on Apache2 and in directory "/demo". Inside this directory there is:

  • v1/index.html
  • v2/index.html

I want to redirect like this:

  • "/demo", "/demo/" and "/demo/*" => v1/index.html
  • "/demo/static", "/demo/static/" and "/demo/static/*" => v2/index.html

I tried this, but it didn't work:

RewriteCond %{REQUEST_URI} !static [NC]
RewriteRule .* v1/index.html [L]

RewriteCond %{REQUEST_URI} static [NC]
RewriteRule .* v2/index.html [L]

Anyone with an idea how to make this work?

Additional details: Root directory is here: /var/www/dev and contains my directory demo . .htaccess is in inside the directory demo .

What about:

RewriteEngine On
RewriteRule .*demo/static.* v2/index.html [L] 
RewriteRule .*demo.* v1/index.html

Since I don't know what is the document root here, I used .*, so it can catch more than you want, but this can be a starting point.

Maybe that's a solution?

RewriteRule ^static/?$ v2/index.html [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ v1/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM