首先,我知道有很多類似這個問題的問題。我已經閱讀了所有我能找到的內容,但是我在其他地方看到的解決方案似乎並不適合我。我真的希望有人能在這裏給我一些見解。隱藏文件擴展名並重定向到https
我試圖使用Apache的.htaccess
指令強制特定頁面在我的服務器上使用ssl。除了這些指令外,我還使用一些重寫來掩蓋.php
和.html
擴展名。我創建了一個頁面https-test.html
。我想那個頁面專門總是重定向所以它使用HTTPS和使.html
被剝去,像https://www.example.com/https-test
但是,我似乎總是與一個循環結束了。閱讀Apache文檔6小時讓我更接近,但我仍然錯過了一些東西。
下面是我註釋的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太多次重定向。
非常感謝。您的更改肯定會讓事情變得更清晰,更易於理解。 這些規則適用於'.php'和'.html'重寫。不幸的是,我仍然在爲'https:// www.example.com/https-test'獲取重定向循環。我真的不明白。 – wrydere
將301更改爲302以清除緩存並查看是否有幫助。如果有效,那麼你可以將它改回301. –
清除了我的緩存,試過不同的瀏覽器,仍然得到一個循環... – wrydere