如何让 MAMP 读取 .htaccess 文件
我正在尝试让 .htaccess
在 MAMP 中工作。 .htaccess
的内容是一个简单的重定向行,但整个 .htaccess 文件似乎没有任何效果,即使我将其更改为包含无效数据也是如此。
我需要更改 MAMP 中的任何设置才能启用 .htaccess
文件吗?
I am trying to get the .htaccess
working in MAMP. The content of the .htaccess
is a simple redirect line, but the entire .htaccess file seems to have no effect, even when I change it to contain invalid data.
Is there any settings within MAMP I need to change to enable .htaccess
files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在
/Applications/MAMP/conf/apache
上的httpd.conf
中,找到:替换
None
替换为全部
。重新启动 MAMP 服务器。
In
httpd.conf
on/Applications/MAMP/conf/apache
, find:Replace
None
withAll
.Restart MAMP servers.
转到
/Applications/MAMP/conf/apache
上的httpd.conf
并查看LoadModule rewrite_module module/mod_rewrite.so
行是否已取消 -评论(开头不带#)并更改这些
从...
到此:
Go to
httpd.conf
on/Applications/MAMP/conf/apache
and see if theLoadModule rewrite_module modules/mod_rewrite.so
line is un-commented (without the # at the beginning)and change these
from ...
To this:
我正在使用 MAMP(今天下载),也遇到了这个问题。问题出在该版本的 MAMP 堆栈的默认 httpd.conf 指令的第 370 行左右。查看 httpd.conf 的第 370 行左右,您会发现:
您需要更改:AllowOverride None
至:允许覆盖全部
I'm using MAMP (downloaded today) and had this problem also. The issue is with this version of the MAMP stack's default httpd.conf directive around line 370. Look at httpd.conf down at around line 370 and you will find:
You need to change: AllowOverride None
To: AllowOverride All
如果您有 MAMP PRO,您可以设置像 mysite.local 这样的主机,然后从主窗口的“高级”面板中添加一些选项。只需打开“索引”和“多视图”选项即可。 “包含”和“FollowSymLinks”应该已经被选中。
If you have MAMP PRO you can set up a host like mysite.local, then add some options from the 'Advanced' panel in the main window. Just switch on the options 'Indexes' and 'MultiViews'. 'Includes' and 'FollowSymLinks' should already be checked.
我在重写时遇到的问题是 Codeigniter 等的一些 .htaccess 文件似乎
在 MAMP 中不起作用......至少对我来说。
The problem I was having with the rewrite is that some .htaccess files for Codeigniter, etc come with
Which doesn't seem to work in MAMP...at least for me.
我刚刚下载了 MAMP,也遇到了同样的问题。正在读取
.htaccess
文件(因为 Apache 在添加AllowOverride All
时返回 500),但重定向被忽略,因为mod_rewrite
未加载。修复起来很容易:/Applications/MAMP/conf/apache/httpd.conf
,找到包含#LoadModule rewrite_module module/mod_rewrite.so
的行(我的文件中的第 179 行)安装),然后删除前导的#
。现在大多数 PHP 项目都使用 mod_rewrite,它应该默认启用。
I've just downloaded MAMP and had the same issue. The
.htaccess
file was being read (since Apache returns a 500 when addingAllowOverride All
), but redirects were ignored becausemod_rewrite
was not loaded. It's easy to fix:/Applications/MAMP/conf/apache/httpd.conf
, find the line containing#LoadModule rewrite_module modules/mod_rewrite.so
(line 179 on my install) then remove the leading#
.Most PHP projects use mod_rewrite these days, it should be enabled by default.
我有 MAMP v 6.6.2(2022 年),我试图通过将 '.htaccess' 文件添加到我的本地主机 Apache 上,使 php 友好 URL 工作。网站根目录(“localhost/mywebsite/.htaccess”):
这不起作用。但我在真实域托管的 cPanel 上对其进行了测试,并且运行良好。
因此,我尝试使用以下建议更改 httpd.conf:
最后我提出了一个建议:
我只是注释掉了“.htaccess”(位于“localhost/mywebsite/.htaccess”)文件中的第二行代码,就是这样:
在它开始工作后,我恢复了所有更改在httpd.conf文件中,我已经完成了上面的操作,并且它仍然有效。
I have MAMP v 6.6.2 (year 2022), and I was trying to make working php friendly URLs on my localhost Apache, by adding '.htaccess' file to my website root directory ("localhost/mywebsite/.htaccess"):
Which didn't work. But I tested it on cPanel hosting on a real domain and it worked fine.
So I have tried to change httpd.conf with these advises:
In the end I came up to an advise:
I simply commented out the second line of the code in my '.htaccess' (located at "localhost/mywebsite/.htaccess") file and that's it:
After it started to work I reverted all the changes in httpd.conf file, I have done above, and it was still working.
只需从该行中删除“#”即可。
在
/Applications/MAMP/conf/apache
中的httpd.conf
中just remove the "#" from this line.
In
httpd.conf
in/Applications/MAMP/conf/apache