Pet*_*rne 8 apache .htaccess mamp
我正在使用mod_rewrite将所有请求路由到index.php.
我的文件夹结构如下:
/Users/Peter/Projects/Framework
/.htaccess
/index.php
Run Code Online (Sandbox Code Playgroud)
在我的.htaccess文件中,我有以下内容:
RewriteEngine on
RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
我访问时工作正常projects.localhost/framework/example.
我还设置了以下别名:Alias /~alias/Users/Peter/Projects
当我导航到http://projects.localhost/~alias/framework/example我的错误日志中出现404错误和以下内容时:File does not exist: /Users/Peter/Projects/framework/example
当我使用别名URL时,似乎没有调用.htaccess文件(在.htaccess文件中输入giberish在使用别名URL时不会触发任何类型的错误似乎证实了这一点).
AllowOveride设置为All.
如何在使用别名URL时使.htaccess正常工作并且重写规则是否始终一致地应用,而不管URL(别名或别名)?
编辑:导航projects.localhost/~alias/framework/index.php/example也工作正常,确认别名正常工作(除了没有应用.htaccess规则).
dan*_*eth 11
我发现你的问题有同样的问题.从@Gerbens评论我设法找到 Apache手册的这一部分,其中指出:
#
# /abc/def/.htaccess -- per-dir config file for directory /abc/def
# Remember: /abc/def is the physical path of /xyz, i.e., the server
# has a 'Alias /xyz /abc/def' directive e.g.
#
RewriteEngine On
# let the server know that we were reached via /xyz and not
# via the physical path prefix /abc/def
RewriteBase /xyz
# now the rewriting rules
RewriteRule ^oldstuff\.html$ newstuff.html
Run Code Online (Sandbox Code Playgroud)
将重写基础添加到别名目录中的.htaccess文件解决了我的问题.
所以在你的情况下
RewriteEngine on
RewriteBase /~alias
RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3493 次 |
| 最近记录: |