![](/img/trans.png)
[英].htaccess - 301 redirect move all pages to https:// - except 1 page?
[英].htaccess 301 redirect for all https to http EXCEPT ONE PAGE
这是我目前在.htaccess文件中的代码:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我知道关于重写的杰克...而且关于这个主题的所有其他帖子确实不符合我的标准,我不太了解该语言来尝试和破译它。
基本上我需要的是这个:
我上面的代码有效,但对于我需要https的1页,它将URL重写为http。 那一页必须是https。
谢谢,克里斯
Apache / 2.2.6(Win32)mod_ssl / 2.2.8 OpenSSL / 0.9.8g PHP / 5.2.6
我在本地进行了测试,所有用例似乎都运行良好。 如果您还有其他问题,请随时提出。
# Rewrite Rules for example.com
RewriteEngine On
RewriteBase /
# Redirect from example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Turn SSL on for payments
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/payments\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Turn SSL off everything but payments
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/payments\.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
重要! 当用户从任何带有www的 https页面导航到没有 www的任何https页面时,他被要求接受非www域的安全证书。
例如(YES =请求接受证书,NO - 相反):
1) https://www.asdf.com/payments.php - YES (www.asdf.com)
2) http://www.asdf.com/phpinfo.php - NO
3) https://asdf.com/phpinfo.php - YES (asdf.com)
4) https://www.asdf.com/phpinfo.php - NO
我试图重新排序.htaccess中的规则但没有成功。 如果有人找到更好的解决方案,我们将非常感激。
除了威廉的伟大解决方案,你可以在https rewriterule之前否定请求uri
RewriteCond %{REQUEST_URI} !^/?payments\.php
这是一个很好的帖子,它似乎正确地重定向到http,但我想要一些如下的东西
RewriteCond %{HTTP_HOST} ^site\.com
RewriteRule (.*) http://www.site.com/$1 [R=301,L]
#RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^products https://www.site.com/products/ [R=301,L]
# Disable SSL on pages other than payments.php
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^products
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
# Require SSL on payments.php
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^products\/?$
RewriteRule ^(.*)$ https://www.site.com/$1 [R=301,L]
RewriteCond $1 !^(index\.php|images|js|css|static|img|payment|robots\.txt|blank.gif)
RewriteRule ^(.*)$ index.php/$1 [L]
我的网址是http://www.sitename.com,并且正斜杠是可选的,我需要的是如果网址中没有类似产品的文字那么它需要http://并且如果有一个字符串产品那么uri应该是https://
该怎么做...当我尝试它时会进入循环...重定向循环。
我正在使用codeigniter框架工作,我已从网址中删除index.php。
所以,如果发生http://sitename.com/products之类的事情,那么我希望它是https://sitename.com/products
如果网址中没有产品,那么它应该重定向到http://
# Rewrite Rules for example.com
RewriteEngine On
RewriteBase /
# Redirect from example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# Disable SSL on pages other than payments.php
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^payments\.php$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# Require SSL on payments.php
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^payments\.php$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
我没有测试它,但这样的东西应该工作
编辑:已更新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.