Apache-2.2

無法讓 mod_rewrite 在 Mac OSX Mountain Lion 上工作

  • December 7, 2012

我已經嘗試了所有我能想到的方法,但它仍然不起作用。我正在嘗試從 Larry Ullman 的 Advanced PHP book 中獲取範常式式碼來工作。他的指示有點缺乏,所以我不得不做一些研究。這是我配置的:

使用者名.conf

<Directory "/Users/me/Sites/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

httpd.conf

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

DocumentRoot "/Users/me/Sites"

<Directory />
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>


<Directory "Users/me/Sites">  
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

.htaccess

<IfModule mod_rewrite.so>

RewriteEngine on
RewriteBase /phplearning/ADVANCED/ch02/

# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1

RewriteLog "/var/log/apache/rewrite.log" 
RewriteLogLevel 2
</IfModule>

沒有任何效果,它甚至不會記錄到 rewrite.log 文件。我做錯了什麼?僅供參考,即使我設置了一個非常簡單的規則或使用根作為重寫基礎,它仍然失敗。我還驗證了 mod_rewrite 模組正在執行。我真的很生氣。

喬爾,

嗨 - 剛剛遇到了同樣的問題。看到這個文章:

https://apple.stackexchange.com/questions/47526/enable-url-rewriting-mod-rewrite-using-htaccess-files-in-sites-on-lion

並更改了我的username.conf文件

<Directory "/Users/myusername/Sites/">
   Options Indexes MultiViews
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

<Directory "/Users/myusername/Sites/">
   Options Indexes MultiViews FollowSymlinks
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

現在mod_rewrite正在為我工作。

引用自:https://serverfault.com/questions/455190