apache - .htaccess HTTPS 并删除 index.php

标签 apache .htaccess mod-rewrite url-rewriting

我找到了这个问题的几个答案,但略有不同,有趣的是它对我不起作用。

我的目标是将任何 url 重写为 HTTPS 并删除 index.php

基本上我想要的是合并以下两个 htaccess 文件,但我对 htaccess 语法有些陌生:

RewriteEngine On
RewriteBase /

# If needed add 'www'
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]

最佳答案

尝试这个 :

RewriteEngine On

RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]

关于apache - .htaccess HTTPS 并删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34198999/

相关文章:

linux - Apache Webserver - 如何写入权限设置为 755 而不是 777 的目录/文件

php - 在 ubuntu 上安装 php datastax 驱动

apache - 为什么服务器错误页面上的 CSS 不起作用?

.htaccess - 在 drupal 7 中更改 CDN 中的视频内容类型(mime 类型)

php - 管理面板的 htaccess 重写规则

php - Fat Free 框架中 mod_rewrite 的简单问题

css - 使用 Apache mod_rewrite 禁用 IE pre SP2 的压缩

php - Apache 的 mod_rewrite 和 %{REQUEST_URI} 问题

.htaccess - 410 状态代码所需的 mod_rewrite 帮助

php - 并发请求 - Codeigniter 或 Apache 2.4 或 MySQL