3

私の既存のものは私のURLから完全に.htaccess削除されます:index.php

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|docs|cache)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>

.htaccessサイト全体をSSLで実行する必要があり、ホスティング会社のPagoda Boxには、に切り替えるための独自の編集httpがありhttpsます。

RewriteCond %{HTTP:X-Forwarded-Proto} = http
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]

これは、最初の条件ステートメントの最後に追加された場合にのみ機能し、その時点で完全に機能します。つまりhttps、ネイキッドURLに追加し、を削除しindex.phpます。

ただし、アドレスバーでsfromを選択して削除すると、が戻ってきて、URLの最後のセグメントが繰り返されます。で始まる完全なURLを入力すると、リダイレクトされて完全に機能します。カーソルをの前に置いて削除した場合にのみ、サイトが壊れます。httpsindex.phphttp://s

この新しい条件とルールが既存のファイルと競合しないようにする方法についてのアイデアはありますか?

4

3 に答える 3

3

最初にhttpからhttpsへのリダイレクトを配置してみてください。!httpsまた、書き換えの条件として使用するのがおそらく最善です。したがって、.htaccessの書き換えセクションは次のようになります。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R]

#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|docs|cache)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
于 2012-08-27T21:30:46.813 に答える
3

CI /パゴダボックスのユーザーの場合、これが私のために働いたものです:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

RewriteBase /

#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|js|docs|cache)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>

RewriteBaseはhttpsリダイレクトの後にあり、[L]は処理を終了することに注意してください。

于 2012-08-27T23:37:20.807 に答える
1

私の好みは、.htaccessを使用する代わりに、仮想ホスト内でこのタイプのリダイレクトを構成することです。

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost *:443>
   ServerName secure.example.com
   DocumentRoot /path_to_webroot/
   SSLEngine On
</VirtualHost>
于 2015-09-02T18:38:00.953 に答える