htaccess的作品在本地主机,但在EC2实例不工作 [英] htaccess works in localhost but doesn't work in EC2 instance

查看:207
本文介绍了htaccess的作品在本地主机,但在EC2实例不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的htaccess文件适用于本地主机,但是当我把它部署到EC2实例不起作用。

我使用的MacBook和取景器中我看不到htaccess文件,我想也许它没有被复制到EC2实例,但我不认为这是问题,因为当我复制的项目,我可以看到在我的编辑htaccess的文件。

有什么使mod-rewrite在EC2 Linux实例?如果有,我没有做到这一点,或者使mod-rewrite为默认?

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$ /index.php/$1 [L]
 

解决方案

我拼凑来自不同岗位的一些信息,所以我想我会提出了一个答案。

  1. 当保罗评论说,如果你正在运行的Amazon EC2 Linux的,你可能运行的httpd,而不是Apache的。因此,该文件位于 /etc/httpd/conf/httpd.conf中
  2. 您必须更改文件以root用户。 (从SSH访问)操作:须藤的vim /etc/httpd/conf/httpd.conf中如何修改httpd.conf文件中的Amazon EC2
  3. 的DocumentRoot的/ var / www / html等被列入两个地方对我来说。我不得不改变后续的AllowOverride无的AllowOverride全部在这两个地方。
  4. 重新启动Apache。我重新启动我的整个EC2实例(我的Apache配置为自动启动)虽然刚启动Apache应该工作。但我看到的变化工作。

我试图让一个.htaccess文件相同的变化(除去URL中的index.php在code点火器应用程序)。希望它可以帮助!

My htaccess file works on localhost but doesn't work when i deploy it to EC2 instance.

I'm using Macbook and in finder i cannot see the htaccess file, i thought that perhaps it didn't get copied to EC2 instance but i don't think this is the problem because when i copy the project i can see the htaccess file in my editor.

Is there something enabling mod rewrite in EC2 linux instance? If there is, i didn't do it or it enables mod rewrite as default?

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

解决方案

I pieced together some info from various posts so I thought I'd put up an answer.

  1. As Paul commented, If you're running Amazon EC2 Linux, you're probably running httpd instead of Apache. The file is therefore in /etc/httpd/conf/httpd.conf
  2. You have to change the file as root user. (from ssh access) Do this: sudo vim /etc/httpd/conf/httpd.conf (How to edit httpd.conf file in AMAZON EC2)
  3. DocumentRoot "/var/www/html" was listed in two places for me. I had to change the subsequent AllowOverride None to AllowOverride All in those two places.
  4. Restart apache. I restarted my whole ec2 instance (i have apache configured to start automatically) although just restarting apache should work. But I see the change is working.

I was trying to make the same changes in a .htaccess file (removing the index.php from urls in a code igniter application). Hope it helps!

这篇关于htaccess的作品在本地主机,但在EC2实例不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆