显然,整个网络上都有大量的mod重写讨论和答案。但是,我很难抓住它们。所以我想我会问这里。
这是我当前在example.com根目录下的目录结构
我想将所有请求重定向到app / index.html,但对/ api的请求除外。
例如:
http://example.com/categories/electronics/ipod实际上就像去http://example.com/app/index.html/categories/electronics/ipod
我希望app / index.html部分被隐藏。
然后,对http://example.com/api的请求将出现异常,因为我将需要向这些url路径发出ajax请求。
感谢您提供的所有帮助/指导。
这可以帮助您(将其放入/.htaccess文件中):
Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{REQUEST_URI} !/api # otherwise forward it to index.html RewriteRule ^.*$ - [NC,L] RewriteRule ^app/. /app/index.html [NC,L]
注意: 对于较新的Apache版本,另请参阅下一个答案,该答案使用起来更容易FallbackResource
FallbackResource