要如何把一个目录下的所有文件到另一个目录? [英] how can i redirect all files in one directory to another directory?

查看:134
本文介绍了要如何把一个目录下的所有文件到另一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搬到了我的文件服务器上的一个新的目录,并想301重定向在新目录中的所有要求的文件。

I've moved the files on my server to a new directory and would like to 301 redirect all the requests to the files in the new directory.

说我有:

  • domain.com/test/apples.php
  • domain.com/test/oranges.php
  • domain.com/test/bananas.php

我如何重定向到:

  • domain.com/apples.php
  • domain.com/oranges.php
  • domain.com/bananas.php

,而不必单独重定向每一个?

without having to redirect each one individually?

推荐答案

假设你正在使用具有mod_rewrite的服务器,在你的根目录下创建一个名为htaccess的文件并插入以下内容:

Assuming you're using a server with mod_rewrite, In your root create a file named ".htaccess" and insert the following contents:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*) http://domain.com/$1 [R=301,L]
</IfModule>

请注意,这将改写每一个文件在测试目录中插入的域。

Note that this will rewrite every single file in the test directory to the domain you inserted.

如果你只想重定向.php文件是:

If you only want to redirect .php files use:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*).php http://domain.com/$1.php [R=301,L]
</IfModule>

注: 不要忘了给domain.com改变你的域名,也是这种类型的重定向会做出的 301重定向是有用的重定向文件永久的URL(这将有助于搜索引擎更新你的链接)。

NOTES: Don't forget to change the domain.com to your domain name, also this type of redirect will make a 301 redirect that is usefull for redirecting PERMANENTLY the url of a file (This will help search engines updating your links).

这篇关于要如何把一个目录下的所有文件到另一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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