文件夹重定向到另一个htaccess的 [英] Redirect folder to another with htaccess

查看:178
本文介绍了文件夹重定向到另一个htaccess的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,文件夹重定向到一个新的。我不希望使用PHP的标题()或类似的东西,我想达到这种效果的mod_rewrite模块和.htaccess文件。

I've got a problem with redirecting folder to a new one. I don't want to use php header() or something similar, i want to achieve this effect with mod_rewrite module and .htaccess file.

我想要做的事情就是重定向 http://domain.com/test/地址 http://domain.com/new/ 。它不重写,它只是将用户从旧到新的地址。我试图用:

The thing I'm trying to do is to redirect the http://domain.com/test/ address to http://domain.com/new/. It's not rewriting, it has to just move the user from old to new address. I was trying to use:

RewriteRule ^test/(.*) new/$1

但它抛出404错误原因目录测试不存在。 我如何可以重定向用户无需创建另一个文件夹?

But it throws 404 error cause catalog test does not exists. How can i redirect the user without creating another folder?

推荐答案

您可以使用外部重定向:

You can use external redirect:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^test/(.*)$ /new/$1 [L,NC,R=302]

如果您不希望外部重定向(在浏览器的URL没有变化),然后删除研究标记:

If you don't want external redirect (no change of URL in browser) then remove R flag:

RewriteRule ^test/(.*)$ /new/$1 [L,NC]

PS:请详细说明:这不是重写,它只是将用户从旧到新的地址

这篇关于文件夹重定向到另一个htaccess的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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