gpt4 book ai didi

php - htaccess 使用 https 将 php 重定向到 html

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:24 25 4
gpt4 key购买 nike

我对激活 SSL 的 htacces 重写规则有问题。

在 htacces 中,我将所有地址 .php 重定向到 .html:

RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]

如果我通过以下方式将 ssl 重定向添加到 https:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

将 php 重写为 html 无效。

例如:

http:// domain.com/test.html --- WORK

http:// domain.com/test.php --> REDIRECTED TO HTML AND WORK

https:// domain.com/test.php --> NOT REDIRECTED -- WORK

https:// domain.com/test.html --> ERROR 404 - PAGE NOT FOUND

已解决这是 https 站点的 apache2 配置问题:

AllowOverride None 更改为AllowOverride All

最佳答案

你的规则是这样的:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{THE_REQUEST} \.php [NC]
RewriteRule ^(.+?)\.php$ $1.html [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)\.html $1.php [L]

关于php - htaccess 使用 https 将 php 重定向到 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23091361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com