【发布时间】:2014-03-07 06:28:38
【问题描述】:
试图让我的 .htaccess 条件工作,但它们似乎无法正常工作,特别是我要删除 /admin/ 目录的第二组 - 它一直被困在第一组条件中
# If the request is either /admin/ or /admin/index.html, rewrite to just admin.html
# http://foo.com/admin/
# http://foo.com/admin/index.html
RewriteCond %{REQUEST_URI} ^/admin/$ [OR]
RewriteCond %{REQUEST_URI} ^/admin/index\.html$
RewriteRule ^ admin.html [L]
# if the request starts w/ /admin/, then remove the /admin folder and continue processing
# http://foo.com/admin/bar/baz.css
RewriteCond %{REQUEST_URI} ^/admin/.*$
RewriteRule ^/admin/(.*)$ /$1
# if any resource is not a directory or file, then rewrite to the index.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
这是一个应该如何工作的映射
group one
- http://foo.com/admin -> http://foo.com/admin.html
- http://foo.com/admin/index.html -> http://foo.com/admin.html
group two
- http://foo.com/admin/bar/baz.css -> http://foo.com/bar/baz.css
- http://foo.com/admin/baz.css -> http://foo.com/baz.css
group three
- http://foo.com/bar/baz.css -> http://foo.com/bar/baz.css(假设 /bar/baz.css 存在)
- http://foo.com/bar/baz.css -> http://foo.com/index.html(假设 /bar/baz.css 不存在)
【问题讨论】:
标签: apache .htaccess mod-rewrite