0

我正在为一家公司更新一个项目。我将文件传输到我的本地主机。所以项目在“localhost/project/”中。当我在浏览器中打开网站时,所有链接都指向“localhost/filename”,目录从项目文件夹向上一级。我做了一些研究,注意到有人建议更改 htaccess,但仍然无法得到正确的结果。和建议请让我知道。如果你想要我的任何东西,请问。感谢!

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

开始 :

http://localhost/projectfolder/

<a href="/" title="">Home</a>

导致 :

http://localhost/

配置文件:

$config['base_url'] = 'http://localhost/projectfolder/';
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
$config['url_suffix'] = ".html";
$config['language'] = "english";
$config['charset'] = "UTF-8";
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['permitted_uri_chars'] = 'a-z & + 0-9~%.:_\-,\'?';
$config['enable_query_strings'] = FALSE;
$config['controller_trigger']   = 'c';
$config['function_trigger']     = 'm';
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['cache_path'] = '';
$config['encryption_key'] = "";
$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['global_xss_filtering'] = FALSE;
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';
4

4 回答 4

1

您可能需要打开 config.php 文件并将 base_url 值更改为 localhost 或可能 localhost:8080(或 localhost 使用的任何端口)。

编辑

问题是您的所有锚标记都使用硬编码值,例如/主页。

在服务器上,这将正常工作,因为您的域类似于go example.comto /,您说的是 go to example.com/

在 codeigniter 中创建链接的正确方法是使用anchor()帮助程序,或者像您的项目一样手动创建锚标记,但在 href 中使用base_url()或使用。site_url()

如何修复主页链接的示例如下:

<a href="<?php echo base_url(); ?>/">blah</a>

它可能适用于您的所有链接,只需在您的 href 值前面加上 base_url,但这取决于链接中的值。

这是 codeigniter 辅助方法的链接 - http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

看一下codeigniter手册对您来说是最有利的,因为它非常好。

于 2013-02-22T15:39:26.713 回答
0

试试这个简单的 .htaccess 它似乎对我有用:你的缺少 ReWriteBase


<IfModule mod_rewrite.c>

    RewriteEngine on
    RewriteBase /projectfolder/

    # If the start of the URL doesn't match one of these...
    RewriteCond $1 !^(index\.php|robots\.txt|uploads|css|images|js)

    # Route through index.php
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

如果这对你有用,我想你可以从修复你的 ReWriteBase 开始。

请注意,当您将此 htaccess 文件上传到您的主机并且默认 base_url 更改为 www.example.com 之类的内容时,您必须将 ReWriteBase 更改为 /

并且不要忘记<?php echo base_url() ?>在可能的情况下在您的链接中使用。

我希望这会有所帮助。

于 2013-02-25T07:51:24.383 回答
0

在配置文件中使用它:

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your project folder  name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

在 .htaccess 中使用它

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

并使用以下命令启用重写模式

a2enmod rewrite

并编辑文件 /etc/apache2/sites-enabled/000-default

change all the AllowOverride None to AllowOverride All. 
于 2013-02-25T08:02:49.070 回答
0

更改以下行

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

to

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

希望它会奏效。

于 2013-02-23T05:54:00.203 回答