我们在ec2上有一台ubuntu机器作为服务器,默认/var/www/html
有一个到/home/ubuntu
的sym链接
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 Rewrite。)
答案 0 :(得分:2)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /website/public_html/app/index.php/$1 [L]
我认为RewriteBase是问题,因为它复制了RewriteRule中的规则
答案 1 :(得分:0)
有两个问题:
正如@ the-agony上面提到的,RewriteBase可能会复制规则,所以切换到:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /website/public_html/app/index.php/$1 [L]
此外,通过
检查日志 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文件中。