2017-01-25 12 views
-1

私は複数の投稿があることを知っていますが、他の回答では解決できません。.htaccess、HTTPSを強制してindex.phpを削除する

私はこれを試しました:htaccess force www and remove index.php.htaccess force HTTPS成功なし。

私のサイトには、ルータを実行するindex.phpがあります。実際にはリンク "/ about"はindex.php(リンク内で削除する)から管理されます。

これが私の現在のhtaccessです:

<IfModule mod_rewrite.c> 

    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC] 
    RewriteCond %{HTTP_HOST} !=localhost [NC] 
    RewriteCond %{HTTP_HOST} !=127.0.0.1 
    RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
    RewriteCond %{THE_REQUEST} ^.*/index.php 
    RewriteRule ^(.*)index.php$ %{HTTP_HOST}/$1/ [R=301,L] 

</IfModule> 

それはindex.phpのために完璧に動作します(実際には、それはindex.phpをを削除し、URLを書き換えます)。

example.comからhttps://www.example.comとこれは大丈夫です、私はこれが欲しいです!)から書き直すことができます。しかし、から書き換えません。http://www.example.comからhttps://www.example.comです。

たとえば、「http://www.example.com/this/is/a/not/link/secure」というリンクはそのままです。 しかし、 "https://www.example.com/this/is/a/not/link/secure"へのリダイレクトを希望します

ありがとうございました。

EDIT:anubhava答えごとに、これは新しい全体のhtaccessです:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule .* index.php [L,QSA] 

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^(?!localhost$|127\.0\.0\.1$)(?:www\.)?(.+)$ [NC] 
RewriteRule^https://www.%1%{REQUEST_URI} [R=301,L,NE] 

RewriteCond %{THE_REQUEST} /index.php [NC] 
RewriteRule ^(.*)index\.php$ /$1/ [R=301,L,NC,NE] 

今では二重のドメインでhttps://www.example.com/www.example.com//?id=12http://www.example.com/apiv2/member-card?id=12を書き換える..... http://example.com/apiv2/member-card?id=12として 同じことがhttps://www.example.com/www.example.com//?id=12

に書き換えられてしまいました
+0

プロキシパスの使用はどうですか? http://stackoverflow.com/questions/16130303/apache-config-how-to-proxypass-http-requests-to-https#16146460 – Hackerman

答えて

0

両方の条件にリダイレクトする最初のルールは[OR]句が必要です。

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^(?!localhost$|127\.0\.0\.1$)(?:www\.)?(.+)$ [NC] 
RewriteRule^https://www.%1%{REQUEST_URI} [R=301,L,NE] 

RewriteCond %{THE_REQUEST} /index.php [NC] 
RewriteRule ^(.*)index\.php$ /$1/ [R=301,L,NC,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule^index.php [L] 

この変更をテストする前に、ブラウザのキャッシュをクリアしてください。

+0

ありがとうございます。しかしあなたのルールでは、このリンク:http://www.example.com/apiv2/member-card?id=12 https://www.example.com//?id=12にリダイレクトされます。 middle – sineverba

+0

いいえ、このルールは完全なURIである '%{REQUEST_URI} 'を使用しているため、URIから何も削除しません。 .htaccessに他のルールがあるかもしれません。完全な.htaccessを投稿できますか? – anubhava

+0

ありがとうございます。私の元の質問の中でhtaccess全体。ありがとうございます – sineverba

関連する問題