PHP Codeigniter - Apache 虚拟主机设置问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4104735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:58:23  来源:igfitidea点击:

PHP Codeigniter - Apache virtual host setup trouble

phpapachecodeignitervhosts

提问by Tilman K?ster

This has been doing my head in. Hope you guys can help. I can't find out where the error lies.

这让我很头疼。希望你们能帮忙。我无法找出错误所在。

httpd-vhosts.conf

httpd-vhosts.conf

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
    DocumentRoot /opt/lampp/htdocs
    ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1>
    DocumentRoot /home/tilman/Sites/mysite/www
    ServerName mysite.lo
</VirtualHost>

/etc/hosts

/etc/hosts

127.0.0.1   localhost
127.0.0.1   mysite.lo

config.php

配置文件

$config['base_url'] = "http://mysite.lo";
$config['index_page'] = "";

www/.htaccess

www/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>

Now http://mysite.loshows me the default controller. http://mysite.lo/index.phpas well. So does http://mysite.lo/index.php/welcome.

现在http://mysite.lo向我展示默认控制器。http://mysite.lo/index.php以及。也是http://mysite.lo/index.php/welcome

But http://mysite.lo/welcomedoesn't.

http://mysite.lo/welcome没有。

http://localhost/mysite/www/welcomeworks as expected.

http://localhost/mysite/www/welcome按预期工作。



edit: I want to move system and application out of the web root. So my file structure looks like this:

编辑:我想将系统和应用程序移出 Web 根目录。所以我的文件结构是这样的:

application/
system/
www/
 '- index.php

In index.php I changed the paths to system and application folder, of course.

当然,在 index.php 中,我更改了系统和应用程序文件夹的路径。

回答by wizardfrag

Sounds like you're having rewritemod/htaccess issues rather than VirtualHost issues. Have you made sure that you've got a block such as

听起来您遇到的是 rewritemod/htaccess 问题而不是 VirtualHost 问题。你确定你有一个块,比如

<VirtualHost *:80>
  ServerName mysite.lo
  <Directory /home/tilman/Sites/mysite>
    AllowOverride All
  </Directory>
</VirtualHost>

somewhere within your config files? The fact that /index.php and /index.php/welcome work, tell me that it's the rewrite mod that's not functioning...

在你的配置文件中的某个地方?/index.php 和 /index.php/welcome 工作的事实,告诉我这是重写 mod 不起作用......

回答by Martin Bean

In your virtual host, do you not need this?

在你的虚拟主机中,你不需要这个吗?

<VirtualHost 127.0.0.1>
    DocumentRoot /home/tilman/Sites/mysite
    ServerName mysite.lo
</VirtualHost>

I'm not sure you needed the wwwportion.

我不确定你需要www那份。