如何在URL的子路径内对单页应用程序进行htaccess? [英] How make htaccess for single-page app within a sub-path in URL?
本文介绍了如何在URL的子路径内对单页应用程序进行htaccess?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望有一个单页应用程序,但只能在一个子网址之内,例如:
I want to have a single-page app, but only within a sub URL like:
//The following would all be valid, but handled by the "index.html"
//at http://www.test.com/webapp
http://www.test.com/webapp
http://www.test.com/webapp/settings
http://www.test.com/webapp/start
我希望所有URL看起来都与上面完全相同,但可以通过以下方式处理:http://www.test.com/webapp/index.html
.
I want all the URLs to look exactly like above, but be handled by: http://www.test.com/webapp/index.html
.
我还希望该页面处理以下 不是 的URL:
I also want the following URLs to not be handled by that page:
http://www.test.com
http://www.test.com/contact
http://www.test.com/about
我该怎么做?
常规单页浏览
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [QA,L]
</ifModule>
推荐答案
只需添加答案以供参考.
@Croises的通信:
The commnet from @Croises:
相同(使用[QSA]而不是[QA]),但在webapp目录中"
"The same (with [QSA] not [QA]) but in the webapp directory"
为我工作.
.htaccess"必须位于子目录中.
示例工作".htaccess":
Example working ".htaccess":
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [QSA,L]
</ifModule>
唯一的区别是"[QA,L]"与"[QSA,L]"
The only diference is "[QA,L]" to "[QSA,L]"
这篇关于如何在URL的子路径内对单页应用程序进行htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文