htaccess的是使用别名的URI时忽略

编程入门 行业动态 更新时间:2024-10-25 18:30:56
本文介绍了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 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时忽略

本文发布于:2023-11-02 08:32:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:的是   别名   htaccess   URI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!