php - CodeIgniter:使用 HTTPS 和 AWS 时如何从 url 中删除 index.php

标签 php .htaccess codeigniter amazon-web-services

我使用 HTTPS 作为主要 url,并且根据 Google SEO 指南,我必须设置以下重定向

  1. http://example.com/https://example.com
  2. http://www.example.com/https://example.com
  3. https://www.example.com/https://example.com

我配置的重定向非常适用于主页。但是对于内部页面,只有第一个有效,而第二个和第三个在 url 中添加 index.php。

示例

https://www.example.com/index.php/mobiles/apple/apple-iphone-sehttps://example.com/index.php/mobiles/apple/apple-iphone-se

我在 .htaccess 中使用以下代码

RewriteEngine On

#Block access for libwww-perl user-agent
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]


RewriteBase /

# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]



RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^52\.34\.179\.108
RewriteRule (.*) https://priceoye.pk/$1 [R=301,L]
  • 托管:AWS (httpd)
  • 网址:PriceOye[点]pk

最佳答案

RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC] 上方添加以下两行解决了问题

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

关于php - CodeIgniter:使用 HTTPS 和 AWS 时如何从 url 中删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36444935/

相关文章:

php - 告诉丢失 3 个或更多连续记录的最佳方法

php - 如何在MySql中存储多个选择选项以便于搜索

wordpress - 移动 Wordpress 站点子目录错误

php - .htaccess不适用于所有链接

.htaccess - htaccess 将域重定向到 https,将子域重定向到 https,将非 www 重定向到 www

php - 如果此人存在则 MySQL 更新

php - 如何在现有的网络项目上实现翻译?

php - 从多个关系表查询数据

php - Codeigniter - 加入同一个表并用数组搜索

php - 在 IIS 上部署 PHP 应用程序