2016-07-15 3 views
1

まず、私はこれに似た質問がたくさんあることを知っています。私は見つけることができるすべてを読んだが、私が他のところで見ている解決法は私にとってはうまくいかないようだ。私は本当に誰かがここに私にいくつかの洞察力を与えることができることを望んでいる。ファイルの拡張子を隠してhttpsにリダイレクト

Apacheの.htaccessディレクティブを使用して、固有のページに強制的にsslを使用しようとしています。これらのディレクティブに加えて、私は.php.htmlという拡張機能をマスクする書き換えをいくつか使用しています。

私はページ、https-test.htmlを作成しました。私はそれがhttpsを使用していますので、そのページが、具体的に常にリダイレクトされますので、.htmlhttps://www.example.com/https-test

のように、剥ぎ取らされることをしかし、私は常にループで終わるように見えるしたいです。 6時間Apacheのドキュメントを読んで私を近づけましたが、私はまだ何かが欠けています。

以下は、私の注釈付きhtaccessファイルです。

RewriteEngine on 

# If port is insecure... 
RewriteCond %{SERVER_PORT} ^80$ 
# And requested URI is /https-test... 
RewriteCond %{REQUEST_URI} ^(.*/)https-test$ [NC] 
# Then point the server to the secure url: 
RewriteRule . "https://www.example.com/https-test" [L,R] 


# The next few lines try matching extensionless requests to .php files 
# If the requested file is not a directory... 
RewriteCond %{REQUEST_FILENAME} !-d 
# And we CAN find a .php file matching that name... 
RewriteCond %{REQUEST_FILENAME}\.php -f 
# Then point us to that .php file and append the query string. 
RewriteRule ^(.+)$ $1.php [L,QSA] 


# These next few lines were added by the previous project owner 
# They're supposed to redirect requests like /foo.html to /foo, 
# But I suspect these might be the culprit 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)/$ /$1 [R=301,NE,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ /$1.html [NE,L] 


# Next few lines are legacy SEO stuff, some pages were linked to as 
# php but now are html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} .php$ 
RewriteRule ^(.*).php$ /$1.html [L,NE] 

これは私のhtaccessのコードです。 Chromeのhttp://www.example.com/https-testにアクセスすると、www.mysite.comがあなたを何度もリダイレクトしてしまいます。

答えて

1

おそらくコードを少し書き直すべきです。あなたは、両方の拡張子のないファイルをphpとhtmlにマッチさせようとしており、それぞれの条件を考慮しているように見えません。あなたは、同じことをやろうとしていないことを確認する条件を追加する必要があります。

コードをバックアップし、コードをこれに置き換えて試してみてください。試す前にすべてのキャッシュをクリアしてください。

RewriteEngine on 
# If port is insecure... redirect for a specific page 
RewriteCond %{HTTPS} !^on [OR] 
RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteRule ^http-test/?$ https://www.example.com%{REQUEST_URI} [R=301,L] 

# Next few lines are legacy SEO stuff, some pages were linked to as 
# php but now are html 
RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.php 
RewriteRule^/%1? [R=301,L] 

# The next few lines try matching extensionless requests to .php files 
# If the requested file is not a directory and php file exists 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.+)$ $1.php [L,QSA] 

#remove trailing slash and is not a php file 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php !-f 
RewriteRule ^([^\.]+)/$ /$1 [R=301,NE,L] 

#finally redirect extensionless URI to html 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ /$1.html [NE,L] 

注これは完全にテストしていません。

+0

ありがとうございます。あなたの変更は、物事をきれいにして理解しやすくします。 これらのルールは、 '.php'や' .html'の書き換えに有効です。残念ながら、私はまだ 'https:// www.example.com/https-test'のリダイレクトループを取得しています。私は本当にそれを得ることはありません。 – wrydere

+1

301を302に変更してキャッシュをクリアし、それが役立つかどうかを確認します。それが動作すれば、それを301に戻すことができます。 –

+0

キャッシュから離れて、別のブラウザを試しても、まだループが発生しました... – wrydere

関連する問題