【问题标题】:Removed WWW from URL in codeigniter, controller doesn't access从 codeigniter 中的 URL 中删除了 WWW,控制器无法访问
【发布时间】:2015-05-13 12:59:46
【问题描述】:

当我运行应用程序时,我想在本地主机上运行我的 CodeIgniter 应用程序,URL 看起来像 https://www.localhost/projects/4all/
然后我对.htaccess 进行了更改,www 已删除,但我的控制器现在无法访问。例如

当我输入 localhost/projects/4all/ 时,它会显示一个空白页。

它不会重定向到routes.php中定义的控制器


.htaccess 在我进行更改之前

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^(www)\.(.*)\.(.*)\.(.*) [NC]
RewriteRule ^(.*)$ http://%2.%3.%4/$1 [R=301,QSA,L]

#force www on production domain

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



DirectoryIndex index.php
Options -Indexes

RewriteRule ^combine/(.*)$ /application/cache/smarty/cached/$1 [L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|sitemap\.rss)

RewriteRule ^(.*)$ index.php?/$1 [L]

.htaccess 修改后:

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

如果需要一些额外的数据,请给我评论。

【问题讨论】:

  • no mine is deffrent 我已经删除了 index.php 和 www,我的问题是删除 www 和 index.php 后没有显示默认控制器
  • 可能是您的新.htaccess 导致apache 错误。查看apache错误日志,看看是否是这个原因。

标签: php codeigniter


【解决方案1】:

您不能在 localhost 上运行像 https://www.localhost/projects/4all/ 这样的基本 URL。 应指定为http://localhost/projects/4all/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 2016-06-12
    • 1970-01-01
    • 2018-01-10
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多