htaccess 在 localhost 中工作,但在 EC2 实例中不起作用 [英] htaccess works in localhost but doesn't work in EC2 instance
问题描述
我的 htaccess 文件在 localhost 上工作,但当我将它部署到 EC2 实例时不起作用.
My htaccess file works on localhost but doesn't work when i deploy it to EC2 instance.
我正在使用 Macbook 并且在 finder 中我看不到 htaccess 文件,我认为它可能没有被复制到 EC2 实例,但我认为这不是问题,因为当我复制项目时我可以看到我的编辑器中的 htaccess 文件.
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.
在 EC2 linux 实例中是否有启用 mod 重写的功能?如果有,我没有这样做,或者它默认启用 mod 重写?
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.
- 正如 Paul 评论的那样,如果您运行的是 Amazon EC2 Linux,则您可能运行的是 httpd 而不是 Apache.因此该文件位于
/etc/httpd/conf/httpd.conf
- 您必须以 root 用户身份更改文件.(来自 ssh 访问)这样做:
sudo vim/etc/httpd/conf/httpd.conf
(如何在亚马逊 EC2 中编辑 httpd.conf 文件) DocumentRoot "/var/www/html"
为我列出了两个地方.我不得不在这两个地方将后续的AllowOverride None
更改为AllowOverride All
.- 重启apache.我重新启动了我的整个 ec2 实例(我将 apache 配置为自动启动),尽管只是重新启动 apache 应该可以工作.但我看到变化正在奏效.
- 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
- 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) DocumentRoot "/var/www/html"
was listed in two places for me. I had to change the subsequentAllowOverride None
toAllowOverride All
in those two places.- 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.
我试图在 .htaccess 文件中进行相同的更改(从代码点火器应用程序中的 url 中删除 index.php).希望能帮到你!
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 在 localhost 中工作,但在 EC2 实例中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!