htaccess的是使用别名的URI时忽略 [英] .htaccess is ignored when using an aliased URI

查看:117
本文介绍了htaccess的是使用别名的URI时忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mod_rewrite的所有请求路由到index.php。

I am using mod_rewrite to route all requests to index.php.

我的文件夹结构如下:

/Users/Peter/Projects/Framework
    /.htaccess
    /index.php

在我的.htaccess文件我有以下几点:

In my .htaccess file I have the following:

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

这工作得很好,当我访问 projects.localhost /框架/例子

This works fine when I visit projects.localhost/framework/example.

我也有以下别名设置:     别名/〜别名/用户/彼得/项目

I also have the following alias set up: Alias /~alias /Users/Peter/Projects

当我浏览到的http://projects.localhost/~alias/framework/example 我得到一个404错误,在我的错误日志中的以下内容:文件不存在:/用户/彼得/项目/框架/例子

When I navigate to http://projects.localhost/~alias/framework/example I get a 404 error and the following in my error log: File does not exist: /Users/Peter/Projects/framework/example

看来,当我用别名URL(打字giberish到.htaccess文件中使用别名URL似乎证实了这一点时,不会触发任何类型的错误).htaccess文件不会被调用。

It seems that the .htaccess file isn't being called when I use the aliased URL (typing giberish into the .htaccess file doesn't trigger any kind of error when using the aliased URL seems to confirm this).

AllowOveride设置为全部。

AllowOveride is set to All.

我要如何使用别名URL时的.htaccess的工作和有重写规则统一适用的URL,无论(化名或不化名)?

How do I get .htaccess working when using the aliased URL and have the rewrite rules apply consistently regardless of the URL (aliased or not aliased)?

编辑:导航到 projects.localhost /〜别名/框架/ index.php文件/例子也能正常工作,确认别名正常工作(除了没有适用于它的htaccess的规则)。

Navigating to projects.localhost/~alias/framework/index.php/example also works fine, confirming that the alias is working properly (apart from not having the .htaccess rules applied to it).

推荐答案

我发现有同样的问题你的问题。从@Gerbens发表评论我设法找到 Apache的手册,该手册规定的这部分

I found your question having the same issue. and from @Gerbens comment I managed to find this part of the Apache manual which states:

#
#  /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

在别名目录添加重写基地.htaccess文件解决了我的问题。

Adding a rewrite base to the .htaccess file in the aliased directory solved my issue.

所以,你的情况

RewriteEngine on
RewriteBase /~alias
RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]

这篇关于htaccess的是使用别名的URI时忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆