将整个站点重定向到子文件夹(Redirect entire site to a sub folder)

编程入门 行业动态 更新时间:2024-10-24 22:23:55
将整个站点重定向到子文件夹(Redirect entire site to a sub folder)

我正在尝试使用以下Redirect命令将我的整个站点重定向到根目录中的子文件夹。

Redirect 301 / http://example.com/folder/

但是,当我打开网站时,它会被重定向到http://www.example.com/folder/folder/folder/folder/folder/folder/folder...

我在这里做错了吗?

I am trying to redirect my entire site to a subfolder present in the root directory using the following Redirect command.

Redirect 301 / http://example.com/folder/

However, when I open the website, it gets redirected to something like http://www.example.com/folder/folder/folder/folder/folder/folder/folder...

Am I doing something wrong here?

最满意答案

是的,你正在重定向以/开头的任何东西,当然包括/folder/它只是保持重定向。 在不排除该部分的情况下,您无法将整个网站重定向到自身的一部分。

改为使用它:

RewriteEngine on RewriteCond %{REQUEST_URI} !^/folder/ RewriteRule ^(.*)$ /folder/$1 [NE,R=301,L]

它将重定向不在/folder/任何内容。

要仅重定向主页,请改用:

RewriteEngine on RewriteRule ^$ /folder/ [R=301,L]

Yes, you're redirecting anything starting with / so of course that includes /folder/ and it just keeps redirecting. You can't redirect your whole site to a part of itself without excluding that part.

Use this instead:

RewriteEngine on RewriteCond %{REQUEST_URI} !^/folder/ RewriteRule ^(.*)$ /folder/$1 [NE,R=301,L]

It will redirect anything that is not in /folder/.

To only redirect the homepage, use this instead:

RewriteEngine on RewriteRule ^$ /folder/ [R=301,L]

更多推荐

Redirect,folder,http,电脑培训,计算机培训,IT培训"/> <meta name="descript

本文发布于:2023-08-07 21:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   重定向   站点   Redirect   site

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!