.htaccess 从子目录重写为根目录 [英] .htaccess rewrite from subdirectory to root
问题描述
我对 mod_rewrite 规则有一些困难.我想重写任何请求
I have some difficulties with the mod_rewrite rules. I want to rewrite any request on
www.example.com/dev/*
到
www.example.com/*
例如当请求url是www.example.com/dev/index.php
时,响应应该是www.example.com/dev/index.php
,不仅是 url 看起来像是来自根目录,而且它实际上使用的是根目录中的 index.php
.
For example when the request url is www.example.com/dev/index.php
, the response should be www.example.com/dev/index.php
, and not just that the url looks like it's from the root directory, but it is actually using the index.php
from root directory.
我已经尝试了有效的 mod_alias
I have tried the mod_alias which works
RedirectMatch (^/dev/)(.*) http://www.example.com/$2
但是不能用mod_alias来应用ip地址条件,所以还是需要用mod_rewrite解决.
But it is not possible to apply ip address conditions with mod_alias, so I still need a solution with mod_rewrite.
有人可以分享一些知识吗?谢谢.
Would anyone share some knowledge please? Thanks.
推荐答案
这样的事情怎么样?
RewriteRule ^dev/(.*)$ $1
这需要在根文件夹中,或应用于主要的 Apache 配置(不在 .htaccess 中).
This would need to be in the root folder, or applied to the primary Apache configuration (not in .htaccess).
关于 .htaccess 重定向的通常规则适用 - 包括 RewriteEngine on
、Options FollowSymLinks
和 AllowOverride FileInfo
包含在某处.http://httpd.apache.org/docs/2.2/上的完整详细信息mod/mod_rewrite.html#rewriterule.
The usual rules about .htaccess redirects apply - including that RewriteEngine on
, Options FollowSymLinks
, and AllowOverride FileInfo
are included somewhere. Full details at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule.
这篇关于.htaccess 从子目录重写为根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!