【问题标题】:URL rewriting - removing folder structure displayed in URL - AngularJS+PHPURL重写-删除URL中显示的文件夹结构-AngularJS + PHP
【发布时间】:2018-03-22 07:55:06
【问题描述】:

我有一个用 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

而我希望 url 是

http://localhost:443/PageName

谁能告诉我如何做到这一点。如何从 URL 中删除文件夹结构

【问题讨论】:

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


    【解决方案1】:

    以下是修复方法。

    我们将使用 $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);
    });
    

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

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

    【讨论】:

      猜你喜欢
      • 2018-05-25
      • 2020-09-06
      • 2023-04-03
      • 1970-01-01
      • 2023-03-09
      • 2012-09-22
      • 1970-01-01
      • 2015-10-30
      • 2019-09-10
      相关资源
      最近更新 更多