去除角网址# [英] Removing the # in Angular URLs

查看:122
本文介绍了去除角网址#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个放置在服务器的Apache2与供应与后端的通信,也承载网站的一个小实例的NodeJS一个AngularJS(1.4.5)的网站,我用的Apache2 站点可用重定向端口的.conf 文件

I have an AngularJS (1.4.5) website that is placed on a apache2 server with a small NodeJS instance that serves the communication with the backend and also hosts the website, I use apache2 sites-available.conf file for redirecting the port

的URL看起来今天这个样子:

The URL looks like this today:

http://prod.mywebsiteurl.com/myapp/#/mp

最后一个路径是动态的,当角应用启动时,它需要的最后一个参数有:(我和$ routeProvider

The last path is dynamic, when the Angular app is started, it takes the last parameter with: (I've configured this with $routeProvider

dynamicUrl = $routeParams.dynamicUrl;

的init()功能。

当启用 html5mode

$locationProvider.html5Mode(true);

我无法访问网站:

I can't access the website:

http://prod.mywebsiteurl.com/myapp/mp

它给出​​了一个错误的Apache2

It gives an apache2 error.

Cannot GET /MP (404)

不过,如果我键入旧地址,用重定向到该网站的没有

不知道如何解决这个问题?这是一个Apache2的配置?如果是这样?我该怎么做?我是一个真正的Apache2小白。

Any idea how to solve this? Is this a apache2 configuration? If so? How do I do it? I am a real apache2 noob.

我想我必须有一个.htaccess文件,并使用这个小重写规则。

I think I have to have a .htaccess file and use this little rewrite rule.

RewriteEngine On  
  # If an existing asset or directory is requested go to it as it is
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]

  # If the requested resource doesn't exist, use index.html
  RewriteRule ^ /index.html

我发现这个页面上:<一href=\"https://ngmilk.rocks/2015/03/09/angularjs-html5-mode-or-$p$ptty-urls-on-apache-using-htaccess/\" rel=\"nofollow\">https://ngmilk.rocks/2015/03/09/angularjs-html5-mode-or-$p$ptty-urls-on-apache-using-htaccess/

但我使用一个节点作为网络服务器,所以我真的不知道在何处放置文件,服务器是Ubuntu的服务器。我把它放在了根的NodeJS,但似乎并没有很好地工作。

But I'm using a Node as the webserver, so I really don't know where to place the file, the server is a Ubuntu server. I placed it in the NodeJS root, but that did not seem to work very well.

任何帮助AP preciated。

Any help appreciated.

推荐答案

我想,你的角度,你的应用程序只有一个入口点(index.html的),然后在内部路由会为你做的一切。你必须在节点要做的是每一个电话你得到回报的index.html。

I guess, for your angular app you have just one entry point (index.html) and then the internal routing will do everything for you. What you have to do in node is every call you get return the index.html.

不幸的是你正在使用的节点什么,如果一个框架与否苏没有说明。假设你有一个前preSS实例上运行,你可以因为这样做如下:

Unfortunately sou did not state what you were using in node, if a framework or not. Assuming you have an express instance running, you can do as follows:

var express = require('express');

var server = express();
server.use('/public', express.static(__dirname + '/public'));

server.get('/*', function(req, res){
    res.sendFile(__dirname + '/index.html');
});

var port = 8000;
server.listen(port, function() {
    console.log('server listening on port ' + port);
});

server.get('/ *'这将基本上接受任何电话,总是会返回index.html的。所以你的角度应用程序可以启动

server.get('/*' this will accept any call basically and will always return index.html. so your angular app can start

这篇关于去除角网址#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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