重写Apache 2的规则具有角JS使用 [英] rewrite rules for apache 2 to use with angular js

查看:134
本文介绍了重写Apache 2的规则具有角JS使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,有很多mod-rewrite讨论和解答整个网络上的。不过,我有一个很难把握它们。所以,我想我会问这里。

Obviously, there are a lot of mod rewrite discussions and answers all across the web. However, I am having a hard time grasping them. So I thought I would ask here.

我所要求的重写规则做安迪乔斯林在这里评论解释说: http://stackoverflow.com/a/11100438

I'm asking for rewrite rules to do what Andy Joslin explained in the comments here: http://stackoverflow.com/a/11100438

这是我的当前目录结构在example.com

This is my current dir structure at the root of example.com


  • 应用程序/

  • 应用程序/ index.html的(对角JS应用程序的根)

  • API(这将是用于API。我会发送Ajax请求,从这里,从一个角度symfony的2个应用程序。)

我想重定向所有请求到App,除了请求/ API / index.html的。

I would like to redirect all requests to app/index.html except for requests to /api.

例如:

<一个href=\"http://example.com/categories/electronics/ipod\">http://example.com/categories/electronics/ipod实际上是喜欢去<一个href=\"http://example.com/app/index.html/categories/electronics/ipod\">http://example.com/app/index.html/categories/electronics/ipod

我想为应用程序/ index.html的部分被隐藏然而

I would like for the app/index.html part to be hidden however.

然后,有将是请求 http://example.com/api 一个例外,因为我需要做的Ajax请求这些URL路径。

Then, there would be an exception for requests to http://example.com/api because I will need to make ajax requests to those url paths.

感谢您的任何和所有帮助/指导。

Thanks for any and all help/guidance.

推荐答案

下面的东西,让你去(把这个你/.htaccess文件中):

Here's something to get you going (put this inside your /.htaccess file):

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 2的规则具有角JS使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆