2016-08-27 14 views
0

私の.htaccessファイルの設定が失われています。私はスリムなフレームワークで処理されるクライアントの部分(angular.jsアプリ)とapiのルートを提供するウェブサイトを持っています。角度およびAPIルートを提供する.htaccessファイルの設定

私のhtmlページはui-routerで提供されますが、ページの更新を処理するためには、私はURL書き換えを行う必要があります。

これまでのところ、私のファイルです:

DirectoryIndex index.html index.php 

# 
# Redirect all to index.php 
# 
RewriteEngine On 

# if a directory or a file exists, use it directly (static assets) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

#if route starts with "api", route to index.php (slim framework) 
RewriteRule ^api/ index.php [L] 
#else (it means we are serving the angular routes) 
RewriteRule ^(.*) /index.html [NC,L] 

それが機能していない、もちろん、です。実際の問題は、私のロジックが最初は良いかどうか(あるいは私は遠く遠くまで...)、そしてそれを書く方法がわからないということです。(私はApacheの構文が初めてです。すべてを理解する)。

答えて

1

APIのhtaccessの

2つの仮想ホストの場合:それが存在する場合は、フロントの仮想ホストが以外(要求されたファイルを提供します

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 (html5mode) 
RewriteRule^/index.html 

# Redirect /api to API virtual host 
<Location /api> 
    ProxyPass http://127.0.0.1:8090 # Change here to the API virtual host binding 
</Location> 

RewriteEngine On 

# Redirect Trailing Slashes 
RewriteRule ^(.*)/$ /$1 [L] 

# Redirect Root 
RewriteRule ^$ api.php [L] 

# Handle API Requests 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^api.php [L] 

フロントバーチャルホスト/ api/*)、そうでない場合はindex.htmlを提供します。すべての/ apiリクエストはAPI仮想ホストに転送されます。 API仮想ホストは既存のファイルを提供するか、API呼び出しを処理するapi.phpに書き換えます。

1台の仮想ホストと

<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

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] 


RewriteCond %{REQUEST_URI} ^/api/ 
RewriteRule^api.php [L] 

# If the requested resource doesn't exist, use index.html (html5mode) 
RewriteRule^/index.html [L] 

WARNING上記と同じ動作:角度アプリに非existantファイルを含むようにしようとすると、無限装荷ループ(インデックスを生成することができます。 html5がロードされると、html5modeなどのためにindex.htmlになる存在しないファイルがロードされます)

+0

複数の仮想ホストを使用することはできません。 .htaccessファイル(OVHホスト) – krakig

+0

2つを組み合わせるだけです。私の編集を参照 –

+0

ありがとう!私は次の 'DirectoryIndex index.html index.php'を追加しなければならなかったので、 '/'ルートが見つかるはずです。どちらの方法でも404エラーが見つかりません。 – krakig

関連する問題