10

Angular.js ルートで大量の記事やスタック オーバーフローの質問を読んだ後でも、手動で更新すると「見つかりません」というエラーが表示されます。

手順:

  1. を参照localhost--> 私の設定 (下記) により、 に移動しlocalhost/homeます。ビューとすべてが正常にロードされます。
  2. ブラウザで更新を押します->ブラウザはこれを表示しますNot Found: the requested /home is not found on this server

この質問はおそらく、ページを更新すると「ページが見つかりません」と表示されるのに最も似ています

私の構成

// Routing configuration.
angular.module('myModule')
    .config(['$routeProvider', '$locationProvider', 
    function ($routeProvider, $locationProvider) {
        // Enable pushState in routes.
        $locationProvider.html5Mode(true);

        $routeProvider
            .when('/home', {
                templates: {
                    layout: '/views/home.html'
                },
                title: 'Welcome!'

            })
            .when('/launchpad', {
                templates: {
                    layout: '/views/layouts/default.html',
                    content: '/views/partials/profile.html'
                },
                title: "Launchpad"
            })
            .otherwise({
                redirectTo: '/home'
            });

    }
]);

私が行った他のこと:

  • index.htmlの には、すでに<base href="/">
  • angular 1.2.1にアップグレード

これが私が試したhtaccessルールです。どれも機能しません。

ページを更新すると「ページが見つかりません」と表示される

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteCond %{REQUEST_URI} !.*\.(css|js|html|png) #Add extra extensions needed.
    RewriteRule (.*) index.html [L]
</ifModule>

http://ericduran.io/2013/05/31/angular-html5Mode-with-yeoman/から

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)       /index.html/#!/$1 
</IfModule>
4

4 に答える 4

8

この .htaccess 設定は私にとってはうまくいきました

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/$
    RewriteRule (.*) /#!/$1 [NE,L,R=301]
</IfModule>
于 2014-08-26T19:22:58.403 に答える
6

これが最適な解決策かどうかはわかりませんが、機能する設定の組み合わせを見つけました。

  • 含めるhashPrefix('!')(下記参照)
  • <base href="/">私のindex.htmlに含まれていませんでした
  • この投稿ごとに、サーバー ファイルのセクションに追加FallbackResource /index.htmlされました。これを設定した後、ローカル設定が何であるかは問題ではないようでした。<Directory PATH_TO_WWW_FILES>.confmod_rewrite
// Routing configuration.
angular.module('myModule')
    .config(['$routeProvider', '$locationProvider', 
    function ($routeProvider, $locationProvider) {
        // Enable pushState in routes.
        $locationProvider.html5Mode(true).hashPrefix('!');

        $routeProvider
            .when('/home', {
                templates: {
                    layout: '/views/home.html'
                },
                title: 'Welcome!'

            })
            .when('/launchpad', {
                templates: {
                    layout: '/views/layouts/default.html',
                    content: '/views/partials/profile.html'
                },
                title: "Launchpad"
            })
            .otherwise({
                redirectTo: '/home'
            });

    }
]);
于 2013-12-11T12:10:26.840 に答える
1

SSL の有無にかかわらず、まだこのエラーに直面している場合:

たとえば、apacheconfigでAllowoverrideを確認してください

<Directory "/var/www/mysite/public_html">
    AllowOverride All
</Directory>

両方のポートにSSLを使用しています

于 2016-04-01T14:05:52.273 に答える