如何让 MAMP 读取 .htaccess 文件

发布于 2024-12-08 10:40:52 字数 187 浏览 0 评论 0原文

我正在尝试让 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

水波映月 2024-12-15 10:40:52
  1. /Applications/MAMP/conf/apache 上的 httpd.conf 中,找到:

    <目录/>
        期权指数 FollowSymLinks
        允许覆盖无
    
    
  2. 替换 None替换为全部

  3. 重新启动 MAMP 服务器。

  1. In httpd.conf on /Applications/MAMP/conf/apache, find:

    <Directory />
        Options Indexes FollowSymLinks
        AllowOverride None
    </Directory>
    
  2. Replace None with All.

  3. Restart MAMP servers.

放赐 2024-12-15 10:40:52

转到 /Applications/MAMP/conf/apache 上的 httpd.conf 并查看 LoadModule rewrite_module module/mod_rewrite.so 行是否已取消 -评论(开头不带#)

并更改这些
从...

<VirtualHost *:80>
    ServerName ...
    DocumentRoot /....
</VirtualHost>

到此:

<VirtualHost *:80>
    ServerAdmin ...
    ServerName ...

    DocumentRoot ...
    <Directory ...>
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory ...>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Go to httpd.conf on /Applications/MAMP/conf/apache and see if the LoadModule rewrite_module modules/mod_rewrite.so line is un-commented (without the # at the beginning)

and change these
from ...

<VirtualHost *:80>
    ServerName ...
    DocumentRoot /....
</VirtualHost>

To this:

<VirtualHost *:80>
    ServerAdmin ...
    ServerName ...

    DocumentRoot ...
    <Directory ...>
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory ...>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
你的呼吸 2024-12-15 10:40:52

我正在使用 MAMP(今天下载),也遇到了这个问题。问题出在该版本的 MAMP 堆栈的默认 httpd.conf 指令的第 370 行左右。查看 httpd.conf 的第 370 行左右,您会发现:

<Directory "/Applications/MAMP/bin/mamp">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

您需要更改: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:

<Directory "/Applications/MAMP/bin/mamp">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

You need to change: AllowOverride None
To: AllowOverride All

毁梦 2024-12-15 10:40:52

如果您有 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.

夜访吸血鬼 2024-12-15 10:40:52

我在重写时遇到的问题是 Codeigniter 等的一些 .htaccess 文件似乎

RewriteBase /

在 MAMP 中不起作用......至少对我来说。

The problem I was having with the rewrite is that some .htaccess files for Codeigniter, etc come with

RewriteBase /

Which doesn't seem to work in MAMP...at least for me.

耳钉梦 2024-12-15 10:40:52

我刚刚下载了 MAMP,也遇到了同样的问题。正在读取 .htaccess 文件(因为 Apache 在添加 AllowOverride All 时返回 500),但重定向被忽略,因为 mod_rewrite 未加载。修复起来很容易:

  1. 打开 /Applications/MAMP/conf/apache/httpd.conf,找到包含 #LoadModule rewrite_module module/mod_rewrite.so 的行(我的文件中的第 179 行)安装),然后删除前导的#
  2. 重新打开 MAMP,单击“停止”,然后单击“启动”以重新启动 Apache。

现在大多数 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 adding AllowOverride All), but redirects were ignored because mod_rewrite was not loaded. It's easy to fix:

  1. Open /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 #.
  2. Reopen MAMP, click Stop then Start to restart Apache.

Most PHP projects use mod_rewrite these days, it should be enabled by default.

┾廆蒐ゝ 2024-12-15 10:40:52

我有 MAMP v 6.6.2(2022 年),我试图通过将 '.htaccess' 文件添加到我的本地主机 Apache 上,使 php 友好 URL 工作。网站根目录(“localhost/mywebsite/.htaccess”):

RewriteEngine On   
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]  

这不起作用。但我在真实域托管的 cPanel 上对其进行了测试,并且运行良好。

因此,我尝试使用以下建议更改 httpd.conf:

  1. https://stackoverflow.com/a/21411933/3936149 - 没有帮助
  2. https://stackoverflow.com/a/7670598/3936149 - 没有帮助
  3. https://stackoverflow.com/a/19204983/3936149 - 没有帮助

最后我提出了一个建议:

  • <一href="https://stackoverflow.com/a/16106140/3936149">https://stackoverflow.com/a/16106140/3936149 - 它成功了!

我只是注释掉了“.htaccess”(位于“localhost/mywebsite/.htaccess”)文件中的第二行代码,就是这样:

RewriteEngine On   
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]  

在它开始工作后,我恢复了所有更改在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"):

RewriteEngine On   
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]  

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:

  1. https://stackoverflow.com/a/21411933/3936149 - didn't help
  2. https://stackoverflow.com/a/7670598/3936149 - didn't help
  3. https://stackoverflow.com/a/19204983/3936149 - didn't help

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:

RewriteEngine On   
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]  

After it started to work I reverted all the changes in httpd.conf file, I have done above, and it was still working.

-小熊_ 2024-12-15 10:40:52

只需从该行中删除“#”即可。

LoadModule rewrite_module modules/mod_rewrite.so

/Applications/MAMP/conf/apache 中的 httpd.conf

just remove the "#" from this line.

LoadModule rewrite_module modules/mod_rewrite.so

In httpd.conf in /Applications/MAMP/conf/apache

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文