.htaccess rewriterule 在 Mac 上无法正常工作
我在我的 mac book pro leopard 上有一个网站项目,我使用内置的 apache2 和 php。我已在 httpd.conf 和 user.conf 中进行配置以使用 htaccess。所做的更改如下:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
<Directory >
AllowOverride All
</Directory>
问题是当我想打开一个像 localhost/~username/site/site/index.php/welcome,index.php 执行一些操作并找到正确的控制器和正确的页面。
但是当我尝试输入 site/welcome 这样的网站时,apache 给出以下错误:
未找到
在此服务器上找不到请求的 URL Users/username/Sites/site/index.php/welcome。
问题是 apache 得到这个就像它确实是一个文件一样,并且错误语句以文件系统的方式给出它,但是这个请求必须被提取到 index.php 。
我的 .htaccess 文件看起来像这样
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>
令我困扰的是,此配置在 Linux 和 Windows 上都有效,但在 Mac 上不起作用。我觉得我注定了:)
I have a website project on my mac book pro leopard, and I am using built in apache2 and php. I've made my configurations in both httpd.conf and user.conf to use htaccess. Changes done like :
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
<Directory >
AllowOverride All
</Directory>
The problem is when i want to open a site like
localhost/~username/site/site/index.php/welcome, index.php does some operations and finds the right controller and the right page.
But when I try to enter site like site/welcome apache gives me the following error :
Not Found
The requested URL Users/username/Sites/site/index.php/welcome was not found on this server.
The problem is apache gets this like it is indeed a file and the error statement gives it in a file system way, but this request must be fetched to index.php instead.
my .htaccess file looks like this
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>
What bothers me that this configuration works on both Linux and Windows but does not work on Mac. I feel doomed : )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也遇到了同样的问题! “DocumentRoot”在 Lion 中对我不起作用。
但这有效:
I met the same problem too! 'DocumentRoot' doesn't work for me in Lion.
But this works:
上将
AllowOverride
设置为All
在 Mac OSX Mountain Lion 上,确保在 Directory /和文档根路径的根目录
:同时确保
FollowSymLinks
> 包含在选项
中。如果您的“index.php-less 漂亮 URL”不在您的 DocumentRoot 上,则在您的 .htaccess 文件中添加以下 RewriteBase 目录(其中存在您的 index.php),如下例所示:
如果您想更改
。 htaccess
文件名更改为.acl
或htaccess.txt
等其他内容,取消 httpd.conf 中以下行的注释并更改
.htaccess中
AccessFileName
指令为extra/httpd-default.conf
文件中您喜欢的任何内容。例如,如果您想将.htaccess
文件更改为htaccess.txt
,请将其更改为:保存它们,在 OSX Mountain Lion 上重新启动 apache Web 服务器,并希望您能够很好,可以走了。
希望这有帮助。
On Mac OSX Mountain Lion, make sure
AllowOverride
is set toAll
on Directory /and root directory of your document root path:
also make sure that
FollowSymLinks
is included inOptions
.if your "index.php-less pretty URL" is not on your DocumentRoot then add the following RewriteBase directory on your .htaccess file where your index.php exists, like the following example:
If you would like to change the
.htaccess
file name to something else like.acl
orhtaccess.txt
, uncomment the following line on your httpd.confand change
.htaccess
inAccessFileName
directive to anything you like inextra/httpd-default.conf
file. For example if you would like to change.htaccess
file tohtaccess.txt
change it to:save them, restart your apache web server on OSX Mountain Lion, and hope you are good to go.
Hope this helps.
您需要将以下行添加到 .htaccess 文件中:
You need to add the following line to your .htaccess file:
我只是遇到了同样的问题,但上面的解决方案对我不起作用,
从一开始删除斜杠就解决了问题(我猜是因为我的浏览器已经在正确的用户下运行)。
所以 RewriteRule ^Register /register.php
变成了 RewriteRule ^Register register.php
这让我发疯!顺便说一句,我正在 mac os 10.8 上运行 xampp (apache 2) 。
I just had the same problem but the solutions above did not work for me,
Removing the slash from the beginning did the trick (i guess because my browser already runs under the correct user).
So RewriteRule ^Register /register.php
Became RewriteRule ^Register register.php
That drove me nuts! BTW I am running xampp (apache 2) on mac os 10.8 .
我遇到了同样的问题,但对我来说问题是
mod_rewrite
未启用。我必须在 /etc/apache2/httpd.conf 文件中取消注释这两行:
之后就不需要使用
RewriteBase
等。I had the same issue but for me the problem was that
mod_rewrite
was not enabled.I had to uncomment these two line in the /etc/apache2/httpd.conf file:
After that there was no need to use
RewriteBase
etc.如果我将 .htaccess 放入 /Library/WebServer/Documents 并打开“localhost/”;对其进行测试,这按预期工作。它只是在“~/Sites”中不起作用。
If I place a .htaccess into /Library/WebServer/Documents and open "localhost/"; to test it, this works as expected. It just doesn't work in "~/Sites".