typecho - apache伪静态里 http跳转https+去掉index.php
PHPz
PHPz 2017-04-11 10:06:12
[PHP讨论组]

我希望可以htpp访问可以跳转到https上,同时去掉访问网站时出现的index.php
访问http://www.域名.com/index.php/1.html可以直接跳转到 https://www.域名.com/1.html

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

现在的伪静态是这样的,但是没办法跳转https

求大神指导。

PHPz
PHPz

学习是最好的投资!

全部回复(5)
伊谢尔伦

现在我的方法是利用php做https的跳转:

<?php if ($_SERVER["HTTPS"] <> "on")
    {
    $xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

    header("Location: ".$xredir);
    }
?>

然后伪静态就正常写去掉index.php的功能:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

算是一种折中的做法,可以实现htpp访问可以跳转到https,同时去掉访问网站时出现的index.php

如果有更好的解决方法,不要忘记告诉我,谢谢~

PHP中文网

跳转和伪静态是两码事
ps:另外请明确跳转的两端,然后设置vhost

伪静态才是rewrite干的事

PHP中文网

楼上正解,http可以用301跳转到https,至于index.php用伪静态解决

ringa_lee

可以这么写:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L] 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

今天做这个也碰到同样的需求,有看到这个链接:https://www.sslshopper.com/ap...
现在我的规则就是上方的,可以使用。

阿神
if ($ssl_protocol = "") {
    return 301 https://$server_name$request_uri; 
} 
if ($host != '你的域名' ) {
    return 301 https://你的域名$request_uri; 
} 

在domain.conf的server段里增加

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号