htacces,将一些子文件夹重定向到另一个子文件夹

时间:2022-07-11 11:10:41

I need to redirect a sub-folder to another sub-folder.

我需要将子文件夹重定向到另一个子文件夹。

My problem is that I want to redirect all the links like

我的问题是,我想重定向所有链接,如

http://example.org/make/satellite/*  or http://example.org/space/satellite/* 

to

  http://example.org/satellite/*

but it does't work. I am using this code

但它不起作用。我正在使用此代码

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.org [NC]
RewriteRule ^(.*)$ example.org$1 [L,R=301]
RedirectMatch 301 ^/satellite/(.*)$ http://example.org/satellite/$1

How can I do this with the htacces file?

如何使用htacces文件执行此操作?

Thanks

2 个解决方案

#1


You have to look for two matches and ignore the first one:

你必须寻找两个匹配并忽略第一个:

RedirectMatch 301 ^/(.*)/satellite/(.*)$  http://example.org/satellite/$2

#2


Try this in your Root/.htaccess file :

在Root / .htaccess文件中尝试:

RedirectMatch 301 ^/make/satellite/(.*)$  http://example.org/satellite/$1 
RedirectMatch 301 ^/space/satellite/(.*)$  http://example.org/satellite/$1 

This redirects http://example.com/make/satellite/ or http://example.com/space/satellite/ to http://example.com/satellite .

这会将http://example.com/make/satellite/或http://example.com/space/satellite/重定向到http://example.com/satellite。

#1


You have to look for two matches and ignore the first one:

你必须寻找两个匹配并忽略第一个:

RedirectMatch 301 ^/(.*)/satellite/(.*)$  http://example.org/satellite/$2

#2


Try this in your Root/.htaccess file :

在Root / .htaccess文件中尝试:

RedirectMatch 301 ^/make/satellite/(.*)$  http://example.org/satellite/$1 
RedirectMatch 301 ^/space/satellite/(.*)$  http://example.org/satellite/$1 

This redirects http://example.com/make/satellite/ or http://example.com/space/satellite/ to http://example.com/satellite .

这会将http://example.com/make/satellite/或http://example.com/space/satellite/重定向到http://example.com/satellite。