URL重写 - 删除URL中显示的文件夹结构 - AngularJS + PHP

时间:2018-03-22 07:55:07

标签: php angularjs .htaccess url-rewriting angular-ui-router

我有一个在angularJS-php中创建的网站。我有两个不同的索引页面。其中一个是“index.php”,另一个是“index.html”。

我在login.tpm.html

中有一个href
<a href="/member/somePage">

在index.php中查找操作。在index.php中,对于给定的URL /请求,我将导航到angular的index.html。在angular index.html中,我使用ui-view渲染角度状态。 的index.php:

 $app->get('/member/somePage', function () use ($app) {
      $app->response()->redirect('folder1/sub-folder2/index.html?v=0301b');
    });

这里的问题是,创建的URL是

http://localhost:443/folder1/sub-folder2/index.html?v=0131b#!/PageName

而我想要网址

http://localhost:443/PageName

任何人都可以告诉我如何实现这一目标。如何从URL

中删除文件夹结构

1 个答案:

答案 0 :(得分:0)

下面是修复程序。

我们将使用$ locationProvider模块并将html5Mode设置为true。

.config(function($routeProvider, $locationProvider) {

    $routeProvider
        .when('/', {
            templateUrl : 'partials/home.html',
            controller : mainController
        })
        .when('/about', {
            templateUrl : 'partials/about.html',
            controller : mainController
        })
        .when('/contact', {
            templateUrl : 'partials/contact.html',
            controller : mainController
        });

    // use the HTML5 History API
    $locationProvider.html5Mode(true);
});

要使用相对链接在您的应用程序周围进行链接,您需要在文档中设置。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<base href="/">
</head>
相关问题