【发布时间】:2014-07-23 15:28:37
【问题描述】:
如果文件夹/文件不存在,我想将域的所有请求静默重定向到子文件夹。
很遗憾,有些场景无法正常工作或以非静默方式工作。
works: http://mydomain.com/index.html -- 显示 production/index.html 的内容
不起作用:http://mydomain.com/ -- 它不显示 production/index.html
works: http://mydomain.com/test/ -- 显示 production/test/index.html 的内容
不起作用:http://mydomain.com/test -- 它将 url(而不是静默重定向)重定向到 http://mydomain.com/production/test/ 并显示 production/test/index.html 的内容
下面是 .htaccess 文件:
Options -Indexes +SymLinksIfOwnerMatch
DirectoryIndex index.php index.html
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/production/
# Don't apply to URLs that go to existing files or folders
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all those to insert /production folder
RewriteRule ^(.*)$ /production/$1 [L]
【问题讨论】:
标签: regex apache .htaccess mod-rewrite