2012-03-30 36 views
0

用户/ /网站目录有可能是一个相当简单的解决方案,但我一直在寻找了两天,并不能找到一个,SOOOO ... mod_rewrite的在OSX

我在OS X机器上开发一个网站(Lion)。工作站点位于/ Users/username/Sites,我已将该目录添加到/etc/apache2/users/username.conf。我可以查看没有问题的页面。

但是...我使用CodeIgniter,我想从URL中删除index.php。这对mod_rewrite来说应该是一个相当简单的工作。我已将.htaccess文件添加到目录中(并在上面的conf文件中设置了AllowOverride All)。谷歌搜索后,我发现我需要选项+ FollowSymLinks设置(我在.htaccess文件中)。

这里的问题是,它似乎从本地主机/〜用户名/到/用户/用户名/站点重写的URL。问题在于,在这种形式下,浏览器只是试图下载index.php文件,而不是执行它。当链接是这会变得更糟,因为/Users//Sites/index.php/controller/function不存在这些文件......笨是指接管在index.php,但只有当它被执行。

所以我不能移除Options + FollowSymLinks,因为它会生成Access Forbidden错误,并且由于上述原因我不能保留它。

有趣的是,把一模一样的网站/资源库/ Web服务器/ Documents目录工作正常。 OS X没有出现在脑海中的FollowSymLinks到该目录,可能是因为它是在httpd.conf设置为DocumentRoot的

我的httpd.conf是股票狮子,除了所有的AllowOverride上/库/ Web服务器/文件。 mod_rewrite已启用。

我username.conf是

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

我在网站的目录的.htaccess文件

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond $1 !^(index\.php|static|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 

很显然,我可以开发上/库/ Web服务器/文档,而是宁愿做它在我的本地文件中。

回答

2

还有就是笨的网站约mod rewrite上一个优秀的wiki页面,它涵盖了所有的你需要对你的.htaccess文件和笨的变化文件本身。

人们很容易忘记在你的配置文件中更改数值,如index_page:

$config['index_page'] = "index.php"; 

$config['index_page'] = ""; 

的例子。该wiki页面上显示htaccess文件是(我已删除评论):

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

如果您发现您需要,只需添加将AddType和选项的属性吧。

+1

RewriteBase就是答案。非常感谢你的帮助。为了将来的参考,我使用了“RewriteBase /〜用户名”。查看日志,RewriteBase在应用重写规则后重写URL前缀,这正是我所需要的。 – mblackwell8 2012-04-01 05:54:31

1

这里有些技巧可能有用

AddType application/x-httpd-php .php 

Options +FollowSymLinks 

RewriteEngine on 
RewriteBase /Users/username/Sites/ 

RewriteEngine on 
RewriteCond $1 !^(index\.php|static|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 

您也可以登录改写日志。不过,建议你删除这些行,您修复后的一切

RewriteLog "/var/log/httpd/rewrite_log" 
RewriteLogLevel 9 
+0

谢谢safarov。你还提到了RewriteBase,它证明了缺失的成分,所以已经投票赞成......但是因为他是第一个而给了cchana答案。也感谢日志,这被证明是有用的。 – mblackwell8 2012-04-01 05:56:25