简体   繁体   English

301重定向到同名文件,同一个服务器,但域名不同

[英]301 redirect to same name file, same server, but differnet domain name

I recently did an overhaul of a website in which we switched to a new master domain name for that website. 我最近对一个网站进行了大修,在该网站中,我们切换到该网站的新主域名。 The old domain is still active, and needed to be redirected to the new domain name. 旧域仍处于活动状态,需要将其重定向到新域名。

The site still has the same root folder, and so there are a couple of files that were updated, but have the same name (ie index.php, about.php, contact.php). 该站点仍具有相同的根文件夹,因此有几个文件已更新,但名称相同(即index.php,about.php,contact.php)。

I manually redirected all the files (via .htaccess) that no longer exist to new files with a manual redirect: 我使用手动重定向将不再存在的所有文件(通过.htaccess)重定向到新文件:

redirect 301 /old_file.php http://www.new_domain.org/new_file.php

However this will not work with the files that have the same name such as "index.php". 但是,这不适用于具有相同名称的文件,例如“ index.php”。 I can still call the site by the old domain name. 我仍然可以使用旧域名来呼叫该网站。 How do I properly refer these files so that I don't have a duplicate penalty from google? 如何正确引用这些文件,以免受到Google的重复处罚?

I tried this and it did not work: 我尝试了一下,但没有成功:

#Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.old_domain.org$[OR]
RewriteCond %{HTTP_HOST} ^old_domain.org$
RewriteRule ^(.*)$ http://www.new_domain.org/$1 [R=301,L]

Thank You 谢谢

  • Clear your browser cache and restart it 清除浏览器缓存并重新启动
  • Make sure mod_rewrite and .htaccess are enabled through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory: 确保通过httpd.conf启用了mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT目录下的.htaccess

Code

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?old_domain\.org$ [NC]
RewriteRule ^ http://www.new_domain.org%{REQUEST_URI} [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM