htaccess将所有页面重定向到单页

时间:2021-10-01 20:08:17

I want to redirect all of my old domain request to my new domain using htaccess file. Below is what I am using but it does not work if the page is not on the new site. For example google index about.htm on the old site but on the new site it does not exist. I would like it to just go to the root in all cases. I know this is not ideal for seo but I don't want any 404s. Any suggestions?

我想使用htaccess文件将我的所有旧域请求重定向到我的新域。以下是我正在使用的内容,但如果页面不在新网站上则无效。例如,旧网站上的谷歌索引about.htm,但在新网站上它不存在。我想在所有情况下都去根。我知道这不适合seo,但我不想要任何404。有什么建议么?

Redirect 301 / http://www.thenewdomain.com/

4 个解决方案

#1


22  

Are you trying to get visitors to old.com/about.htm to go to new.com/about.htm? If so, you can do this with a mod_rewrite rule in .htaccess:

您是否想让访问者访问old.com/about.htm转到new.com/about.htm?如果是这样,您可以使用.htaccess中的mod_rewrite规则执行此操作:

RewriteEngine on

RewriteEngine on

RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]

RewriteRule ^(。*)$ http://www.thenewdomain.com/$1 [R =永久,L]

#2


53  

If your aim is to redirect all pages to a single maintenance page (as the title could suggest also this), then use:

如果您的目标是将所有页面重定向到单个维护页面(因为标题也可以建议),那么使用:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.php$ 
RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
RewriteRule $ /maintenance.php [R=302,L] 

Where 000 000 000 000 should be replaced by your ip adress.

如果你的ip地址应该取代000 000 000 000。

Source:

资源:

http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

#3


11  

This will direct everything from the old host to the root of the new host:

这将指向旧主机到新主机根目录的所有内容:

RewriteEngine on
RewriteCond %{http_host} ^www.old.com [NC,OR]
RewriteCond %{http_host} ^old.com [NC]
RewriteRule ^(.*)$ http://www.thenewdomain.org/ [R=301,NC,L]

#4


3  

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ "http://www.thenewdomain.com/" [R=301,L]

#1


22  

Are you trying to get visitors to old.com/about.htm to go to new.com/about.htm? If so, you can do this with a mod_rewrite rule in .htaccess:

您是否想让访问者访问old.com/about.htm转到new.com/about.htm?如果是这样,您可以使用.htaccess中的mod_rewrite规则执行此操作:

RewriteEngine on

RewriteEngine on

RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]

RewriteRule ^(。*)$ http://www.thenewdomain.com/$1 [R =永久,L]

#2


53  

If your aim is to redirect all pages to a single maintenance page (as the title could suggest also this), then use:

如果您的目标是将所有页面重定向到单个维护页面(因为标题也可以建议),那么使用:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.php$ 
RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
RewriteRule $ /maintenance.php [R=302,L] 

Where 000 000 000 000 should be replaced by your ip adress.

如果你的ip地址应该取代000 000 000 000。

Source:

资源:

http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

#3


11  

This will direct everything from the old host to the root of the new host:

这将指向旧主机到新主机根目录的所有内容:

RewriteEngine on
RewriteCond %{http_host} ^www.old.com [NC,OR]
RewriteCond %{http_host} ^old.com [NC]
RewriteRule ^(.*)$ http://www.thenewdomain.org/ [R=301,NC,L]

#4


3  

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ "http://www.thenewdomain.com/" [R=301,L]