【问题标题】:How to use mod_rewrite on OS X如何在 OS X 上使用 mod_rewrite
【发布时间】:2012-09-25 18:15:55
【问题描述】:

我使用 mac os x 10.6.8,但 mod_rewrite 有问题 - 它不起作用。

我在/etc/apache2/users/my_user.conf/etc/apache2/httpd.conf 中更改了AllowOverride All

.htaccess 代码:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

PHP:

var_dump($_GET['q']);

结果:

Trying: http://localhost/~nonamez123/konkurs/asgfsddsh  

Not Found

The requested URL /Users/nonamez123/Sites/konkurs/index.php was not found on this server.

如您所见,继续重写index.php,但找不到index.php

日志:

127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (3) [perdir
/Users/nonamez123/Sites/konkurs/] strip per-dir prefix:
/Users/nonamez123/Sites/konkurs/asfdasdf -    asfdasdf
127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (3) [perdir
/Users/nonamez123/Sites/konkurs/] applying pattern '^(.*)$' to uri
'asfdasdf'
127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (4) [perdir
/Users/nonamez123/Sites/konkurs/] RewriteCond:
input='/Users/nonamez123/Sites/konkurs/asfdasdf' pattern='!-f' =>
matched
127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (4) [perdir
/Users/nonamez123/Sites/konkurs/] RewriteCond:
input='/Users/nonamez123/Sites/konkurs/asfdasdf' pattern='!-d' =>
matched
127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (2) [perdir
/Users/nonamez123/Sites/konkurs/] rewrite 'asfdasdf' ->
'index.php?q=asfdasdf'
127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (3) split
uri=index.php?q=asfdasdf -    uri=index.php, args=q=asfdasdf
127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (3) [perdir
/Users/nonamez123/Sites/konkurs/] add per-dir prefix: index.php ->
/Users/nonamez123/Sites/konkurs/index.php
127.0.0.1 - - [25/Sep/2012:21:06:13 +0300] [localhost/sid#10080d720][rid#1009d64a8/initial] (1) [perdir
/Users/nonamez123/Sites/konkurs/] internal redirect with
/Users/nonamez123/Sites/konkurs/index.php [INTERNAL REDIRECT]

【问题讨论】:

    标签: php macos apache .htaccess mod-rewrite


    【解决方案1】:

    我不会将您的开发文件放在 ~user/Sites 中,而是将它们放在 /Library/WebServer/Documents 中的网络服务器根目录中。我有更好的运气。

    然后,确保 /etc/apache2/httpd.conf 中的 AllowOverride All 位于标有 <Directory "/Library/WebServer/Documents"> 的目录标签内。 httpd.conf 中有几个 AllowOverride 指令,如果您使用我的方法,您要修改的指令在第 217 行附近。

    还要确保 LoadModule rewrite_module libexec/apache2/mod_rewrite.so 行未注释。

    最后确保使用sudo apachectl graceful 重新启动 apache。

    如果您确实想使用您的用户站点目录,此博客条目有一些提示。 http://johnattebury.com/blog/2012/07/upgrading-to-mountain-lion-forbidden-403-you-dont-have-permission-to-access-username-on-this-server/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 2010-11-30
      • 2014-12-18
      • 2023-04-03
      相关资源
      最近更新 更多