【问题标题】:symbolic links and htaccess on apache2apache2上的符号链接和htaccess
【发布时间】:2017-10-11 19:21:39
【问题描述】:

我们在 ec2 上有一台 ubuntu 机器作为服务器,默认的 /var/www/html 有一个指向 /home/ubuntu 的符号链接

ubuntu@ip-172-XX-XX-XXX:/var/www/html$ ls -al
total 20
drwxrwxrwx 2 root root  4096 Sep 10 02:19 .
drwxr-xr-x 3 root root  4096 Sep 10 02:17 ..
-rw-r--r-- 1 root root 11321 Sep 10 02:17 index.html
lrwxrwxrwx 1 root root    20 Sep 10 02:19 website -> /home/ubuntu/website

目录/home/ubuntu/website 包含

public_html/app/

这是 CodeIgniter 的家(基地)。当我访问网站时

http://ec2-34-XXX-XX-XXX.compute-1.amazonaws.com/website/public_html/app/index.php/login

我可以看到页面加载正确。但是当我以

身份访问它时
http://ec2-34-XXX-XX-XXX.compute-1.amazonaws.com/website/public_html/app/login

我不能 - 它显示

Not Found

The requested URL /website/public_html/app/login was not found on this server.

.htaccess 文件如下:

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

我在这里缺少什么? (Mod 重写已启用。)

【问题讨论】:

  • .htaccess 文件在/website/public_html/app/?
  • 是的,感谢问题现已解决!

标签: php apache .htaccess codeigniter


【解决方案1】:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /website/public_html/app/index.php/$1 [L]

我认为 RewriteBase 是问题所在,因为它复制了 RewriteRule 中的规则

【讨论】:

    【解决方案2】:

    有两个问题:

    1. 正如@the-agony 上面提到的,RewriteBase 很可能复制了规则,所以切换到这个:

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

    2. 此外检查日志通过

      sudo tail /var/log/apache2/error.log

    显示:

        [Wed Oct 11 19:41:36.396178 2017] [core:alert] [pid 30110] [client 130.245.192.0:27286] /var/www/html/website/public_html/.htaccess: Expected </IfModule> before end of configuration
        [Wed Oct 11 19:44:11.269472 2017] [core:alert] [pid 30106] [client 130.245.192.0:13926] /var/www/html/website/public_html/.htaccess: Expected </IfModule> before end of configuration
        [Wed Oct 11 19:44:14.046920 2017] [core:alert] [pid 30108] [client 130.245.192.0:22481] /var/www/html/website/public_html/.htaccess: Expected </IfModule> before end of configuration
        [Wed Oct 11 19:44:15.465143 2017] [core:alert] [pid 30107] [client 130.245.192.0:19889] /var/www/html/website/public_html/.htaccess: Expected </IfModule> before end of configuration
    

    问题出在 /public_html 目录中的 .htaccess 文件上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-16
      • 2018-12-01
      • 2012-03-19
      • 2012-06-09
      • 1970-01-01
      • 2010-11-29
      • 2014-11-22
      • 1970-01-01
      相关资源
      最近更新 更多