У меня проблемы с объединением перезаписи параметров запроса url (fancy-url) с перенаправлением shl .htaccess.
Мой файл .htaccess в настоящее время:
Options +FollowSymLinks
Options -Indexes
ServerSignature Off
RewriteEngine on
RewriteBase /
# in https: process secure.html in https
RewriteCond %{server_port} =443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+).html$ index.php?page=$1 [QSA,L]
# in https: force all other pages to http
RewriteCond %{server_port} =443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+).html$ http://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in http: force secure.html to https
RewriteCond %{server_port} !=443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+).html$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in http: process other pages as http
RewriteCond %{server_port} !=443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+).html$ index.php?page=$1 [QSA,L]
Необычное переписывание URL работает нормально, но перенаправление на / из https не работает вообще.
Если заменить 2 строки, содержащие
RewriteRule ^(.+).html$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
с
RewriteRule ^(.+).html$ https://%{HTTP_HOST}/index.php?page=$1 [QSA,L]
тогда перенаправление https работает нормально, но переписывание причудливых URL не работает.
Можно ли объединить эти два?
Edit:
Желаемые результаты:
1. http://domain.com/secure.html is rewritten to https://domain.com/index.php?page=secure
2. http://domain.com/foo.html is rewritten to http://domain.com/index.php?page=foo
3. https://domain.com/secure.html is rewritten to https://domain.com/index.php?page=secure
4. https://domain.com/foo.html is rewritten to http://domain.com/index.php?page=foo
(мне пришлось поместить их в блок кода, так как для новых пользователей не разрешено более 1 ссылки)
Таким образом, secure.html всегда является https, а foo.html (все остальные страницы) всегда http.
Решение:
Благодаря Gumbo решение:
Options +FollowSymLinks
Options -Indexes
ServerSignature Off
RewriteEngine on
RewriteBase /
# in https: force all other pages to http
RewriteCond %{server_port} =443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+)\.html$ http://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in http: force secure.html to https
RewriteCond %{server_port} !=443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+)\.html$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in https: process secure.html in https
RewriteCond %{server_port} =443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+)\.html$ index.php?page=$1 [QSA,L]
# in http: process other pages as http
RewriteCond %{server_port} !=443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+)\.html$ index.php?page=$1 [QSA,L]