【问题标题】:Hosting Codeigniter site on GoDaddy with shared hosting使用共享主机在 GoDaddy 上托管 Codeigniter 站点
【发布时间】:2014-11-16 08:35:50
【问题描述】:

目录结构(public_html

public html
htpasswds
application
    .htacess
cgi-bin
system
user_guide
index.php

配置文件如下所示:

$config['base_url'] = 'http://www.example.com/index.php/';
$config['index_page'] = 'index.php?';
$config['uri_protocol'] = 'AUTO';
$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = FALSE;

.htaccess文件

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

route.php

$route['default_controller'] = 'welcome';

application->controllers 下我有两个PHP 文件,welcomeabout,其中包含方法。

下面是我生成的链接,分别是

<li><a href='./welcome'>Home</a>
<li><a href='./welcome/first'>first</a></li>    
<li><a href='./welcome/second'>second</a></li>
<li><a href='./third'>Third</a></li>
<li><a href='./fourth>Four</a></li>
<li><a href='./five'>Five</a></li>
<li><a href='./six'>Six</a></li>

如果我手动输入http://www.example.com/index.php/welcome/second,我可以访问该页面。 但我不知道如何生成相同的链接,以及如何摆脱 URL 中的index.php

【问题讨论】:

  • godaddy 也遇到了同样的问题。不幸的是,他们不支持我,我无法删除 godaddy server 上的 index.php。希望您能找到解决方案。
  • &lt;li&gt;&lt;a href='&lt;?php echo base_url(); ?&gt;welcome/first'&gt;first&lt;/a&gt;&lt;/li&gt; 将生成您的链接。顺便说一句,你错过了第一个 li 结束标签
  • 哦!再次错字,以 li 结尾标签。感谢您提供此信息。否则我在超链接中使用硬编码的完整 url 路径。
  • li 元素的结束标记在 HTML 中是可选的,因此除非这是 XHTML,否则&lt;/li&gt; 标记只会使您的文档膨胀。

标签: php .htaccess codeigniter web-hosting shared-hosting


【解决方案1】:

最好使用 Anchor 函数来生成链接。请参阅文档here

htaccess 应该去掉 url 之前的 index.php,你应该把这行改成:

 $config['index_page'] = ''; 

【讨论】:

    猜你喜欢
    • 2020-08-31
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多