如何使用.htaccess将单个网页从一个域重定向到另一个域

时间:2022-08-23 10:11:33

How do I get the following redirect to work?

如何让以下重定向工作?

olddomain.com/employee-scheduling-software.html

To redirect to

要重定向到

newdomain.us/employee-scheduling-software.html

I do have mod_rewrite on, but I'm basically a complete novice in this area

我确实有mod_rewrite,但我在这方面基本上是一个完整的新手

2 个解决方案

#1


6  

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html
</IfModule>

You can change the rule into:

您可以将规则更改为:

RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html [R=301]

which will send a 301 Moved Permanently header to the browser, so it updates its bookmarks and stuff.

它将向浏览器发送301 Moved Permanently标头,以便更新其书签和内容。

#2


0  

You could use this code in .htaccess on olddomain.com:

您可以在olddomain.com上的.htaccess中使用此代码:

RewriteEngine on
RewriteRule ^employee-scheduling-software\.html$ http://newdomain.us/employee-scheduling-software.html [R,QSA]

Since the ^employee-scheduling-software\.html$ is a PERL regex, you need to escape the dot in ".html" with a backslash (\.).

由于^ employee-scheduling-software \ .html $是PERL正则表达式,因此需要使用反斜杠(\。)来转义“.html”中的点。

This will just redirect employee-scheduling-software.html to the new domain. If you want to redirect all files to the new domain, use:

这只会将employee-scheduling-software.html重定向到新域。如果要将所有文件重定向到新域,请使用:

RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.us/$1 [R,QSA]

#1


6  

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html
</IfModule>

You can change the rule into:

您可以将规则更改为:

RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html [R=301]

which will send a 301 Moved Permanently header to the browser, so it updates its bookmarks and stuff.

它将向浏览器发送301 Moved Permanently标头,以便更新其书签和内容。

#2


0  

You could use this code in .htaccess on olddomain.com:

您可以在olddomain.com上的.htaccess中使用此代码:

RewriteEngine on
RewriteRule ^employee-scheduling-software\.html$ http://newdomain.us/employee-scheduling-software.html [R,QSA]

Since the ^employee-scheduling-software\.html$ is a PERL regex, you need to escape the dot in ".html" with a backslash (\.).

由于^ employee-scheduling-software \ .html $是PERL正则表达式,因此需要使用反斜杠(\。)来转义“.html”中的点。

This will just redirect employee-scheduling-software.html to the new domain. If you want to redirect all files to the new domain, use:

这只会将employee-scheduling-software.html重定向到新域。如果要将所有文件重定向到新域,请使用:

RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.us/$1 [R,QSA]