这是我目前在 .htaccess 文件中的代码:
Here is the code I have currently in my .htaccess file:
Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} ^example [NC] RewriteRule ^(.*)$ www.example/$1 [L,R=301] RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI} [L,R=301]我知道 jack 是关于重写的……关于这个主题的所有其他帖子都不符合我的标准,而且我对语言的了解不够,无法尝试破译它.
I know jack about rewrites...and all of the other posts on this subject really don't fit my criteria and I don't know enough about the language to try and decipher it.
基本上我需要的是这个:
Basically what I need is this:
我上面的代码有效,但是对于我需要成为 https 的 1 个页面,它将 url 重写为 http.那一页必须是 https.
The code I have above works, but for the 1 page that I need to be https, it is rewriting the url to http. That one page has to be https.
谢谢,克里斯
推荐答案Apache/2.2.6 (Win32) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.2.6
Apache/2.2.6 (Win32) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.2.6
我已经在本地进行了测试,所有用例似乎都可以正常工作.如果您还有其他问题,请随时提问.
I've tested it locally, all use cases seem to work fine. If you have further questions, feel free to ask.
# Rewrite Rules for example RewriteEngine On RewriteBase / # Redirect from example to www.example RewriteCond %{HTTP_HOST} ^example [NC] RewriteRule ^(.*)$ www.%{HTTP_HOST}/$1 [R=301,L] # Turn SSL on for payments RewriteCond %{HTTPS} off RewriteCond %{SCRIPT_FILENAME} /payments.php [NC] RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L] # Turn SSL off everything but payments RewriteCond %{HTTPS} on RewriteCond %{SCRIPT_FILENAME} !/payments.php [NC] RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L]重要提示!当用户从带有 www 的任何 https 页面导航到任何 https 页面时如果没有 www,他会被要求接受您的非 www 域的安全证书.
IMPORTANT! When the user navigates from any https page with www to any https page without www, he's asked to accept security certificate of your non-www domain.
例如(YES = 请求接受证书,NO - 相反):
For example (YES = request to accept the certificate, NO - opposite):
1) www.asdf/payments.php - YES (www.asdf) 2) www.asdf/phpinfo.php - NO 3) asdf/phpinfo.php - YES (asdf) 4) www.asdf/phpinfo.php - NO我尝试在 .htaccess 中重新排序规则,但没有成功.如果有人找到更好的解决方案,我们将不胜感激.
I tried to reorder rules in .htaccess with no success. If anyone finds a better solution, it'll be highly appreciated.
更多推荐
.htaccess 301 将所有 https 重定向到 http,除了一页
发布评论