【问题标题】:CodeIgniter: How to remove index.php from url when using HTTPS and AWSCodeIgniter:使用 HTTPS 和 AWS 时如何从 url 中删除 index.php
【发布时间】:2016-07-26 11:46:16
【问题描述】:

我使用 HTTPS 作为主要网址,根据 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[dot]pk

【问题讨论】:

  • 您能否澄清一下“第一”、“第二”和“第三”的含义?您指的是帖子开头列出的规则或网址吗?此外,检查 config.php 中 $config['index_page'] 的值并将其设置为 ''(空字符串)。
  • 文章开头列出的网址。 $config['index_page'] 配置正确,因为问题中提到的 url 集 1 正在工作

标签: php .htaccess codeigniter amazon-web-services


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    在您的项目文件夹中创建一个名为“.htaccess”的文件 然后输入这个

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    然后转到应用程序> 配置> config.php

    $config['base_url'] = 'http://localhost/project_name/';
    
    /*
    |--------------------------------------------------------------------------
    | Index File
    |--------------------------------------------------------------------------
    |
    | Typically this will be your index.php file, unless you've renamed it to
    | something else. If you are using mod_rewrite to remove the page set this
    | variable so that it is blank.
    |
    */
    $config['index_page'] = '';
    

    变成这样

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 2015-10-24
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2012-09-21
      • 2011-10-12
      相关资源
      最近更新 更多