只允许相对路径 [英] Allowing relative paths only

查看:238
本文介绍了只允许相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这是一个Apache 的.htaccess 的问题,然而,也许不是。也许我在看从错误的角度问题,因而无法找到妥善的解决办法。

I believe this is an Apache .htaccess issue, and yet, maybe not. Maybe I am looking at the problem from the wrong angle, and thus can't find the proper solution.

我建立一个Web应用程序+混合移动应用程序。我想和大家分享完全相同的code碱基,而无需手动调整任何部署我的应用程序的Andr​​oid或iOS,否则,部署的过程将是哈克和痛苦的。我要的是把Web应用程序库,它推到科尔多瓦的复选框 (你肮脏的男人;)的,它会成功部署。

I am building a web app + hybrid mobile app. I would like to share the exact same code base, without having to tweak anything manually to deploy my app to Android or iOS, otherwise, the process of deploying will be hacky and painful. What I want is to take the web app repository, shove it into Cordova's box (you dirty man ;), and it would deploy it successfully.

现在,有一个问题是,科尔多瓦要求相对路径才能正常工作。例如,这是我包括我的 require.js 文件:

Now, one issue is that Cordova requires relative paths to work properly. For example, this is how I include my require.js file :

<script data-main="library/js/dependencies.js" src="library/js/libs/require.js">
</script>

这适用于混合动力应用的罚款。这工作得很好也大多数Web应用程序的URL的,那些与以下方案:

This works fine on the hybrid app. This works fine also on most of the web app's URLs, those with the following scheme :

domain.com/view_name

然而,这是当我加载从接收URI参数的查看应用程序会发生什么:

However, this is what happens when I load the app from a view that receives URI parameters :

domain.com/view_name/6iwO4NyJqy

的相对路径不妥善解决了。我得到 404错误由于unproper路径。举例来说,这是怎么解决上面的 require.js 文件:

The relative paths are not resolved properly anymore. I get 404 error due to unproper paths. For instance, this is how is resolved the require.js file above :

http://domain.com/view_name/library/js/libs/require.js

VIEW_NAME 位是错误的一部分。它不应该存在。没有它,该文件会被成功找到。

The view_name bit is the wrong part. It should not be there. Without it, the file would be found successfully.

这是我的的.htaccess 文件:

RewriteEngine on
RewriteBase /

# REROUTING EVERYTHING TO index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /index.html [NC,L,QSA]

有没有一种方法来设置我的的.htaccess 文件,这样我就不需要应用程序内修改相对路径,而且还可以让他们妥善解决?

Is there a way to set my .htaccess file, so that I don't need to modify the relative paths within the app, and still can have them resolved properly ?

任何建议是值得欢迎的。

Any suggestion is most welcome.

推荐答案

这不是你的重写规则引起的,这是由于您使用相对路径。

It is not caused by your rewrite rule, it is due to your use of relative paths.

您可以略低于添加此&LT; HEAD&GT; 您网页的HTML部分:

You can add this just below <head> section of your page's HTML:

<base href="/" />

让每一位相对URL 是从基本URL,而不是从当前页面的URL解决。

so that every relative URL is resolved from that base URL and not from the current page's URL.

这篇关于只允许相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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