Php 高级htaccess-301域重定向

Php 高级htaccess-301域重定向,php,.htaccess,redirect,Php,.htaccess,Redirect,我想将我的旧域重定向到新域。我有两个版本的网站-波兰语和英语。我拥有的域名是:live-dent.pl、live-dent.com、live-dent.com.pl和livedent.pl。 我想重定向: (www.)live-dent.pl/index.php,(www.)live-dent.com/index.php,(www.)live-dent.com.pl/index.php和livedent.pl/index.php www.livedent.pl(不带破折号) (www.)liv

我想将我的旧域重定向到新域。我有两个版本的网站-波兰语和英语。我拥有的域名是:live-dent.pl、live-dent.com、live-dent.com.pl和livedent.pl。 我想重定向:

  • (www.)live-dent.pl/index.php,(www.)live-dent.com/index.php,(www.)live-dent.com.pl/index.php和livedent.pl/index.php www.livedent.pl(不带破折号)
  • (www.)live-dent.pl/index_en.php,(www.)live-dent.com/index_en.php,(www.)live-dent.com.pl/index_en.php和livedent.pl/index_en.php www.live-dent.com(带破折号)
为此,我想将404错误重定向到自定义页面。此文件的波兰版本的路径为:

  • www.livedent.pl/404.php,以及
  • www.live-dent.com/404_en.php,英文版(此文件现在不存在)
我现在的代码(感谢@anubhava)是:


规则ErrorDocument 404/404.php不起作用。

假设所有这些域共享同一个文档根:

RewriteCond %{HTTP_HOST} ^(www\.)?live-dent\.(pl|com|com\.pl)$ [OR,NC]
RewriteCond %{HTTP_HIST} ^livedent\.pl$ [NC]
RewriteCond %{THE_REQUEST} \ /+index\.php
RewriteRule ^ http://www.livedent.pl/ [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?live-dent\.(pl|com|com\.pl)$ [OR,NC]
RewriteCond %{HTTP_HIST} ^livedent\.pl$ [NC]
RewriteCond %{THE_REQUEST} \ /+index_en\.php
RewriteRule ^ http://www.live-dent.com/ [L,R=301]

假设所有这些域共享相同的文档根目录:

RewriteCond %{HTTP_HOST} ^(www\.)?live-dent\.(pl|com|com\.pl)$ [OR,NC]
RewriteCond %{HTTP_HIST} ^livedent\.pl$ [NC]
RewriteCond %{THE_REQUEST} \ /+index\.php
RewriteRule ^ http://www.livedent.pl/ [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?live-dent\.(pl|com|com\.pl)$ [OR,NC]
RewriteCond %{HTTP_HIST} ^livedent\.pl$ [NC]
RewriteCond %{THE_REQUEST} \ /+index_en\.php
RewriteRule ^ http://www.live-dent.com/ [L,R=301]

非常感谢你!你知道为什么规则:ErrorDocument 404/404.php不起作用吗?@user2911046你还有其他规则吗?不,我没有。现在我有了:RewriteEngine On RewriteCond%{THE_REQUEST}^[A-Z]{3,}\s/+index_en\.php[NC]RewriteRule^[R=301,L,NC]RewriteCond%{THE_REQUEST}{A-Z]{3,}\s/+index\.php[NC]RewriteRule^/[R=301,L,NC]RewriteCond%{HTTP_HOST}live\.pl$[NC]rule^{REQUEST u URI}[R=301,L]ErrorDocument 404/404.php我现在无法访问服务器,因此这是旧代码。您确定最后一行代码将与您的代码版本一起正常工作吗?非常感谢!你知道为什么规则:ErrorDocument 404/404.php不起作用吗?@user2911046你还有其他规则吗?不,我没有。现在我有了:RewriteEngine On RewriteCond%{THE_REQUEST}^[A-Z]{3,}\s/+index_en\.php[NC]RewriteRule^[R=301,L,NC]RewriteCond%{THE_REQUEST}{A-Z]{3,}\s/+index\.php[NC]RewriteRule^/[R=301,L,NC]RewriteCond%{HTTP_HOST}live\.pl$[NC]rule^{REQUEST u URI}[R=301,L]ErrorDocument 404/404.php我现在无法访问服务器,因此这是旧代码。您确定最后一行将与您的代码版本一起正常工作吗?