Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使http状态码301重定向和404错误处理工作_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php 如何使http状态码301重定向和404错误处理工作

Php 如何使http状态码301重定向和404错误处理工作,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我在服务器上安装了Wordpress,有两个域指向它。计划是建立一个SEO友好的重定向,包括301重定向和404错误处理。我正在使用3个文件:ApacheVirtuaHost、.htaccess和PHPScript(http状态代码404的错误页面) Vhost(Apache) .htaccess和404.php位于文件系统上的/path/to/mydomain 我很难让RewriteRule(301重定向)和ErrorDocument(404错误处理)一起工作。当我输入任何URL时,只要Rew

我在服务器上安装了Wordpress,有两个域指向它。计划是建立一个SEO友好的重定向,包括301重定向和404错误处理。我正在使用3个文件:ApacheVirtuaHost、.htaccess和PHPScript(http状态代码404的错误页面)

Vhost(Apache)

.htaccess和404.php位于文件系统上的/path/to/mydomain

我很难让RewriteRule(301重定向)和ErrorDocument(404错误处理)一起工作。当我输入任何URL时,只要RewriteRule到位,我就会得到“301永久移动”。它完全忽略http状态码404。不幸的是,这会导致Google(据我所知)和其他搜索引擎来降低页面排名(例如重复内容)

我错过了什么?非常感谢您的帮助

期待你们的来信:-)

非常感谢

S.D.

重写规则:

RewriteCond %{HTTP_HOST} ^www\.mydomain-to-be-redirected\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain-with-content.com/$1 [R=301,L]
将所有内容从www.mydomain-to-be-redirected.com重定向到www.mydomain-with-content.com。低于该值的任何内容都不会被使用


在这种情况下,如果页面不存在,www.mydomain-with-content.com将返回404,这似乎是您希望发生的事情。

如果您将所有内容重定向到“mydomain with content.com”,您将永远不会收到404错误!我是这个话题的新手。你能给我一个建议或例子吗?谢谢!
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mydomain-to-be-redirected\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain-with-content.com/$1 [R=301,L]

ErrorDocument 404 /404.php 
RewriteCond %{HTTP_HOST} ^www\.mydomain-to-be-redirected\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain-with-content.com/$1 [R=301,L]