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/*
例如,当您输入的网址 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
但它不可能使用IP地址的条件下mod_alias中,所以我还需要与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叙述上
,有FollowSymLinks
和的AllowOverride FileInfo的
包括地方。全部细节在<一个href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule">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屋!