要求htaccess从https重定向。*

时间:2016-03-03 08:45:38

标签: apache .htaccess redirect

我有一个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]

它工作正常,例如从index / test重定向到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重定向,如url?

1 个答案:

答案 0 :(得分: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]

清除浏览器缓存后进行测试。