重定向网站根子目录 [英] Redirect website root to subdirectory

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

问题描述

我如何可以重定向将Web根目录的所有请求到另一个文件夹(如公共/)?

How can I redirect all requests going to web root to another folder (e.g. public/)?

我已经尝试过这个(的.htaccess的Web根目录):

I've already tried this (contents of .htaccess in web root):

RewriteEngine on
RewriteRule ^(.*)$ public/$1

但现在我有地址重复的内容: address.tld / address.tld /公/

But now I have duplicate content for addresses: address.tld/ and address.tld/public/

我想重定向 address.tld /公/ address.tld / ,所以不会有任何重复,但我不知道如何做到这一点,而不是进入重定向循环......

I would like to redirect address.tld/public/ to address.tld/, so there won't be any duplicates, but I just don't know how to do it and not get into redirecting cycle...

推荐答案

请尝试以下规则:

RewriteCond %{THE_REQUEST} ^GET\ /public/
RewriteRule ^public/(.*) /$1 [L,R=301]
RewriteRule !^public/ public%{REQUEST_URI} [L]

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

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