Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php localhost中的Codeigniter链接已断开_Php_Codeigniter_Hyperlink_Broken Links - Fatal编程技术网

Php localhost中的Codeigniter链接已断开

Php localhost中的Codeigniter链接已断开,php,codeigniter,hyperlink,broken-links,Php,Codeigniter,Hyperlink,Broken Links,我正在为一家公司更新一个项目。我将文件传输到本地主机。所以项目位于“localhost/project/”中。当我在浏览器中打开网站时,所有链接都指向“localhost/filename”,即从项目文件夹向上一级目录。我做了一些调查,发现有人建议更改htaccess,但仍然没有得到正确的结果。请让我知道。如果你需要我帮忙,尽管问。谢谢! RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILE

我正在为一家公司更新一个项目。我将文件传输到本地主机。所以项目位于“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>
Config.php:

$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'] = '';

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

编辑

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

在服务器上,这可以正常工作,因为您的域类似于
example.com
,所以转到
/
,就是说转到
example.com/

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

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

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

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

这里有一个指向codeigniter助手方法的链接-


您最好看看codeigniter手册,因为它非常好。

更改以下行

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

to

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

希望它能起作用。

试试这个简单的方法。htaccess它似乎对我有用:你的缺少了基础



重新启动发动机
重写基本/项目文件夹/
#如果URL的开头与其中一个不匹配。。。
1美元^(索引\.php | robots\.txt |上传| css |图像| js)
#通过index.php路由
重写规则^(.*)$index.php/$1[L]

如果这对你有用的话,我想你可以先修复你的基础

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

在可能的情况下,不要忘记在链接中使用


我希望这会有所帮助。

在配置文件中使用此选项:

$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默认值

change all the AllowOverride None to AllowOverride All. 

什么是你的.htaccess atm?你能用正确的格式将它添加到你的问题中吗?这可能会帮助你:这可能会帮助你:该文件位于何处?/application/config/config.phpOk那么什么url会在浏览器中显示你的应用程序,当你点击一个不起作用的链接时,你会得到什么url?另外,你使用的是mamp还是wamp,或者别的什么?localhost/projectname使用WAMP打开主页,当我点击“主页链接”时,它会将我带到localhost;wamp主页
a2enmod rewrite
change all the AllowOverride None to AllowOverride All.