重写请求到子目录 [英] Rewrite request to a sub directory
问题描述
我有一个目录中的Web应用程序假设 XYZ
。我想所有的请求重定向到一个子目录 WWW
。我目前的.htaccess code是:
I have a web application in a directory suppose xyz
. I am trying to redirect all requests to a sub directory www
. My current .htaccess code is:
RewriteEngine On
RewriteRule (.*) /www/$1 [L]
但是,当我访问 http://example.com/xyz/some_url
的请求重定向到 http://example.com / WWW / some_url
,而 http://example.com/xyz/www/some_url
这是我想要的。
But, when I visit http://example.com/xyz/some_url
the request is redirected to http://example.com/www/some_url
rather http://example.com/xyz/www/some_url
which I want.
更新:对不起,我忘了提及的目录XYZ在我的情况很可能重新命名。因此,这个目录并不需要硬codeD的重写规则
Update: Sorry, I forgot to mention the directory xyz as in my case is likely to renamed. So, this directory doesn't need to be hard coded in the rewrite rule
推荐答案
将在这个规则 /xyz/.htaccess
:
RewriteEngine On
RewriteBase /xyz/
RewriteRule ^((?!www/).*)$ www/$1 [L,NC]
这篇关于重写请求到子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!