2016-03-03 176 views
0

我有一個htaccess讓用戶使用https並實現一些語義網址。 這就是:讓htaccess重定向到https。*

Options -MultiViews 
RewriteEngine On 

RewriteCond %{HTTPS} off [NC] 
RewriteRule ^https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 
RewriteRule ^(index|getReadings|admin|adminNewDesign)\/([A-Za-z]*)$ https://%{HTTP_HOST}/$1.php?id=$2 [L,QSA,NC] 
RewriteRule ^adminNewDesign$ https://%{HTTP_HOST}/adminNewDesign/addingOperators/i [L,QSA,NC] 
RewriteRule ^admin$ https://%{HTTP_HOST}/admin.php [L,QSA,NC] 
RewriteRule ^(index)/(reg)/(byphone|byemail)?$ https://%{HTTP_HOST}/$1.php?id=$2&loginform=$3 [L,QSA,NC] 
RewriteRule ^(index|getReadings|admin|adminNewDesign)/(\w+)/(\d+)/?$ https://%{HTTP_HOST}/$1.php?id=$2&page=$3 [L,QSA,NC] 
RewriteRule ^(index|getReadings)/(fullpage)/(true)/?$ https://%{HTTP_HOST}/$1/php?$2=$3 [L,QSA,NC] 
RewriteRule ^(admin|adminNewDesign)\/([A-Za-z]*)/([A-Za-z]*)$ https://%{HTTP_HOST}/$1.php?id=$2&device=$3 [L,QSA,NC] 
RewriteRule ^adminNewDesign\/(individualAnalogueNotification|analogueNotification|intercomNotification)/record-([0-9]+)\.wav$ https://%{HTTP_HOST}/play_audio.php?recordType=$1&record_id=$2 [L,QSA,NC] 

它正常工作,例如,從指數/測試重定向到https://hostname.ru/index.php?id=test。 但是當我去adminNewDesign它重定向到https://hostname.ru/adminNewDesign/addingOperators/i

當我使用HTTP另一個規則在這裏工作,這一個:

RewriteRule ^(admin|adminNewDesign)\/([A-Za-z]*)/([A-Za-z]*)$ https://%{HTTP_HOST}/$1.php?id=$2&device=$3 [L,QSA,NC] 

但最後重定向現在無法正常工作,它給了404錯誤。 所以看起來像^(admin|adminNewDesign)\/([A-Za-z]*)/([A-Za-z]*)$適合http://hostname.ru/admin但不適合https://hostname.ru/admin。 那麼,我怎樣才能顯示htaccess重定向從https像urls?

回答

0

您在頂部https=>http只需要一個重定向和休息應該是這樣的內部重寫:

Options -MultiViews 
RewriteEngine On 

RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [R=302,NE,L] 

RewriteRule ^(index|getReadings|admin|adminNewDesign)/([A-Za-z]*)/?$ $1.php?id=$2 [L,QSA,NC] 

RewriteRule ^adminNewDesign/?$ adminNewDesign/addingOperators/i [L,QSA,NC] 

RewriteRule ^admin/?$ admin.php [L,QSA,NC] 

RewriteRule ^(index)/(reg)/(byphone|byemail)?/?$ $1.php?id=$2&loginform=$3 [L,QSA,NC] 

RewriteRule ^(index|getReadings|admin|adminNewDesign)/(\w+)/(\d+)/?$ $1.php?id=$2&page=$3 [L,QSA,NC] 

RewriteRule ^(index|getReadings)/(fullpage)/(true)/?$ $1/php?$2=$3 [L,QSA,NC] 

RewriteRule ^(admin|adminNewDesign)/([A-Za-z]*)/([A-Za-z]*)/÷$ $1.php?id=$2&device=$3 [L,QSA,NC] 

RewriteRule ^adminNewDesign\/(individualAnalogueNotification|analogueNotification|intercomNotification)/record-([0-9]+)\.wav$ play_audio.php?recordType=$1&record_id=$2 [L,QSA,NC] 

測試它清除瀏覽器緩存後。

+0

奇怪,但這根本不起作用。 https://domainname.ru/getReadings/icom顯示我404.我清除了我的Chrome瀏覽器緩存並以隱身模式打開它。 –

+0

另外,從我以前的問題的人http://stackoverflow.com/questions/35747480/rewrite-htaccess-for-https 建議添加https://%{HTTP_HOST} /重定向。它效果更好。 –

+0

'getReadings.php'位於何處?什麼是'https'站點的'DocumentRoot'? – anubhava