OSX + Apache2 + httpd.conf + hosts + .htaccess = 不工作
Posted
技术标签:
【中文标题】OSX + Apache2 + httpd.conf + hosts + .htaccess = 不工作【英文标题】:OSX + Apache2 + httpd.conf + hosts + .htaccess = not working 【发布时间】:2011-08-23 16:38:43 【问题描述】:在我的 Mac 上,我正在尝试在本地 php 项目上激活 htaccess 重写规则。这是我的配置:
我使用的是 OSX 10.6.7,Apache2 正在运行,Php5 已激活。
我的项目位置:/Library/WebServer/Documents/my-project/
httpd.conf
[...]
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
DocumentRoot "/Library/WebServer/Documents"
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
<Directory "/Library/WebServer/Documents">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
[...]
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/my-project/"
ServerName my-project.local
</VirtualHost>
my_user_name.conf
<Directory "/Users/my_user_name/Sites/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
主机
127.0.0.1 my-project.local
*.htaccess (/Library/WebServer/Documents/my-project/.htaccess) *
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([0-9]+)\.home\.html$ front/content/home.php?rub=$1
RewriteRule ^([0-9]+)-([0-9]+)-[a-z0-9A-Z'_%?éèàêâûô\-]+\.html$ front/content/article.php?id=$1&rub=$2 [L]
[...]
但是,当我尝试访问时:
http://my-project.local/66-75-one-great-page.html
它不解析为:
http://my-project.local/front/content/article.php?id=66&rub=75
Rhhaaa,有什么想法吗? 谢谢你们:-)
【问题讨论】:
.htaccess: /Library/WebServer/Documents/my-project/.htaccess ...日志中没有什么特别之处。该死!我只是不明白...... :-/ 谢谢你的回答...... 【参考方案1】:您必须在重写规则中的站点名称后包含斜杠。如下更改重写规则并尝试:
RewriteRule ^/([0-9]+)\.home\.html$ front/content/home.php?rub=$1
RewriteRule ^/([0-9]+)-([0-9]+)-[a-z0-9A-Z'_%?éèàêâûô\-]+\.html$ front/content/article.php?id=$1&rub=$2 [L]
【讨论】:
以上是关于OSX + Apache2 + httpd.conf + hosts + .htaccess = 不工作的主要内容,如果未能解决你的问题,请参考以下文章