【问题标题】:CodeIgniter controller and cPanel subfolder has same nameCodeIgniter 控制器和 cPanel 子文件夹具有相同的名称
【发布时间】:2016-05-10 23:34:22
【问题描述】:

使用here 中描述的说明从 URL 中删除“index.php”后,
当我调用与子文件夹同名的 codeIgniter 控制器时,会请求 cPanel 子文件夹。

控制器和子文件夹名称为“sites”。所以,当我要求

example.com/sites

它不请求控制器 example.com/index.php/sites,而是请求子文件夹“sites”。

可以通过删除子文件夹或重命名控制器来解决,但我想知道是否有其他解决方案可以解决此问题。

谢谢!

【问题讨论】:

标签: php .htaccess codeigniter cpanel


【解决方案1】:

您可以通过 htaccess 规则做到这一点。

试试这个规则:-

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
// Below line will controller instead of directory
RewriteRule ^sites/?$ index.php/sites [L]

RewriteCond %{REQUEST_URI} !^/sites
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

希望对你有帮助:)

【讨论】:

  • 如果有用,请接受答案,以便将来的访问者发现它有用:)
  • 删除#RewriteCond %{REQUEST_FILENAME} !-d 使其具有通用性是一种好习惯吗?每次都忽略子目录并发送请求index.php
  • 它没有忽略子目录。查看此链接了解更多详情:- stackoverflow.com/a/34875835/4198099
  • 在那个答案中你说 "-d (is test string a valid directory)"。这是否意味着,如果我们删除它,它将忽略子目录?谢谢!
  • 好的。现在我收到你的问题了。是的,你是对的。如果我们删除它,那么它将忽略子目录。
猜你喜欢
  • 1970-01-01
  • 2017-03-08
  • 1970-01-01
  • 1970-01-01
  • 2014-04-18
  • 1970-01-01
  • 2023-01-11
  • 2013-06-14
  • 1970-01-01
相关资源
最近更新 更多