Apache的文件根重写问题

我目前正在将所有内容redirect到app / index.html,因为我有一个客户端单页面应用程序。 但是,我想跳过实际的文件和目录redirect。 我已经得到这个了。 但是,当我在RewriteCond中添加跳过目录的文件时,它也会计算文档根目录。 这会导致访问文档根目录(如打到http://localhost:8080来列出我的目录内容。 我怎么会得到这个不适用于文档根目录或任何其他更好的方法? PS我也跳过/ api目录。

这是我到目前为止:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/api RewriteRule ^(.*)$ /app/index.html/$1 [NC] 

所以基本上我猜我在问什么:如何跳过除了文档根目录之外的目录?

Krist van BesienKrist van Besien给我的答案的帮助下,我能够find解决办法。

 # not a directory RewriteCond %{REQUEST_FILENAME} !-d [OR] # or if it is the document root RewriteCond %{REQUEST_URI} ^/$ # not a file RewriteCond %{REQUEST_FILENAME} !-f # not /api RewriteCond %{REQUEST_URI} !^/api$ RewriteRule ^(.*)$ portal/index.html/$1 [NC] 

你可以添加一个RewriteCond:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/api RewriteCond %{REQUEST_URI} !^/$ RewriteRule ^(.*)$ /app/index.html/$1 [NC] 

我会build议改变这一行:

 RewriteRule ^(.*)$ /app/index.html/$1 [NC] 

对此; 注意^被删除:

 RewriteRule (.*)$ /app/index.html/$1 [NC]