301 从旧站点文件夹直接到新站点结构

发布于 2024-11-12 04:20:24 字数 245 浏览 2 评论 0原文

提前致谢。

我用新的文件夹结构重新设计了我的网站

旧网站结构: www.domain.com/folder/file.aspx

新站点结构: www.domain.us/folder/file.php

请注意新的 TLD。我有大约 20 个文件夹需要重定向。是否可以使用一个文件来执行此操作,还是必须为从旧站点到新站点的每个单独文件夹执行 301?处理这个问题的最佳方法是什么?

再次, 提前致谢

Thanks in advance.

I have redone my website with new folder structures

Old site structure:
www.domain.com/folder/file.aspx

New site structure:
www.domain.us/folder/file.php

Notice the new TLD. I have around 20 folders that I want to redirect. Is it possible to do this with one file or do I have to do a 301 for each individual folder from the old site to the new site? What is the best way to handle this?

Again,
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

红颜悴 2024-11-19 04:20:24

您应该为此使用 mod_rewrite 。将其放入 FTP 的 public_html 文件夹中的 .htaccess 文件中:

RewriteEngine On
RewriteRule ^([^.]+)\.aspx$ $1.php [L]

这应该确保当有人调用 Banana.aspx 时,他们会得到查看Banana.php

You should use mod_rewrite for that. Put this in the .htaccess file in the public_html folder of your FTP:

RewriteEngine On
RewriteRule ^([^.]+)\.aspx$ $1.php [L]

This should make sure that when someone is calling Banana.aspx they get to see Banana.php.

无语# 2024-11-19 04:20:24

该目录中的 .htaccess 文件优先于父目录中的任何 .htaccess 文件。因此,如果您的每个子目录中已经有 .htaccess 文件,那么将 .htaccess 文件放在根目录中是没有意义的。

从要重定向的每个子目录中删除 .htaccess 文件,并更新根文件夹中的 .htaccess 文件。您可能需要放置 20 个这样的重写规则。 请记住,从子目录中删除 .htaccecss 将删除您[可能]对该文件夹施加的所有限制。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteRule ^folder/file\.aspx$ http://domain.us/folder/file.php [R=301,NC,L]
RewriteRule ^folder2/file\.aspx$ http://domain.us/folder2/file.php [R=301,NC,L]

301 表示永久重定向,NC 表示无情况,L 表示要处理的最后一条规则,如果匹配

OR

更新您要重定向的每个目录中的 .htaccess 文件

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteRule ^(.*)\.aspx$ http://domain.us/folder/$1.php [R=301,NC,L]

#the following might also do; just test it out
#RedirectPermanent (.*)\.aspx$ http://domain.us/folder/$1.php

因此,根据您的情况选择一个。我会选择选项一,以便所有重定向都集中在一个地方。您始终可以将限制从子目录的 .htaccess 移至根目录的 .htaccess。

The .htaccess file in the directory takes precedence over any .htaccess file in the parent directories. So, if you already have .htaccess file in each of your sub-directories then putting an .htaccess file in your root directory makes no sense.

Remove the .htaccess files from each of your sub-directories that you want to redirect and update the .htaccess file in your root folder. You probably need to put 20 rewrite rules like this. Keep in mind that removing .htaccecss from sub-directories will remove all restrictions that you [might] have put on that folder.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteRule ^folder/file\.aspx$ http://domain.us/folder/file.php [R=301,NC,L]
RewriteRule ^folder2/file\.aspx$ http://domain.us/folder2/file.php [R=301,NC,L]

301 for permanent redirect, NC for No Case, L for Last rule to process if matches

OR

Update the .htaccess file in each directory that you want to redirect

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteRule ^(.*)\.aspx$ http://domain.us/folder/$1.php [R=301,NC,L]

#the following might also do; just test it out
#RedirectPermanent (.*)\.aspx$ http://domain.us/folder/$1.php

So,, depending on your situation, you pick one. I'd go with option one so that all redirects are in one place. You can always move the restrictions from subdirectories' .htaccess to root's .htaccess.

做个少女永远怀春 2024-11-19 04:20:24

如果使用301 PHP header()重定向,那么恐怕只能一一完成。

但是,如果您使用 mod_rewrite 来为您处理此问题,那么这是一个供您查看的相关来源: http://www.gnc-web-creations.com/301-redirect.htm

If you use 301 PHP header() redirect, then I'm afraid it can only be done one-by-one.

But if you use mod_rewrite to handle this for you, then this is a relevant source for you to have a look: http://www.gnc-web-creations.com/301-redirect.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文