Apache RewriteRule到子目录 [英] Apache RewriteRule to subdirectory

查看:94
本文介绍了Apache RewriteRule到子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将myhomepage.com/重定向到myhomepage.com/sub/

I need to redirect myhomepage.com/ to myhomepage.com/sub/

当我在apache.org/docs/1.3/misc/rewriteguide.html阅读该指南时,我不知道他们在说什么.因此,我决定友好地问一位专家.我想只需几秒钟就可以解决这个问题.

When I read the guide at apache.org/docs/1.3/misc/rewriteguide.html I have no clue what they are talking about. Hence I decided to friendly ask one of the experts here. I guess it takes just some seconds to figure that rule out.

谢谢卡林.

推荐答案

尝试以下规则:

RewriteRule !^sub/ sub%{REQUEST_URI}

它将在内部将所有不以/sub/(!^sub/)开头的请求的URL路径重定向到/sub/(sub%{REQUEST_URI}).

It will redirect any requested URL path that does not start with /sub/ (!^sub/) internally to /sub/ (sub%{REQUEST_URI}).

此规则适用于文档根目录中的.htaccess配置文件.如果要在httpd.conf中使用它,请在模式前面加上/.

This rule is for the .htaccess configuration file in your document root. If you want to use it in your httpd.conf, prepend the pattern with a /.

如果要进行外部重定向,请在替换之前也添加/并添加[R]标志:

And if you want an external redirect, prepend the substition with a / too and add the [R] flag:

RewriteRule !^sub/ sub%{REQUEST_URI} [R]

这篇关于Apache RewriteRule到子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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