我将网站从http://lifeworkslearningcenter.com移到http://lifeworks.life。我为正常工作的各个网址设置了7个301重定向,并将基本网址重定向到新的基本网址。
现在我需要为剩余的URL,拼写错误等设置一个通配符。现在发生的事情是:7个重定向中未明确涵盖的任何URL将重定向到新的基本URL,然后添加先前输入的尾随URL,结果为404.像这样:
http://lifeworkslearningcenter.com/incorrect-url
https://www.lifeworks.life/incorrect-url
这是我的.htaccess代码,包括之前对wildcard重定向语句的三次尝试:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^about-lifeworks$ "https\:\/\/www\.lifeworks\.life\/team\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^services$ "https\:\/\/www\.lifeworks\.life\/services\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^methodology$ "https\:\/\/www\.lifeworks\.life\/approach\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^sign-up$ "https\:\/\/www\.lifeworks\.life\/enroll\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^rates-and-policies$ "https\:\/\/www\.lifeworks\.life\/policies\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^contact-us$ "https\:\/\/www\.lifeworks\.life\/contact\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
RewriteRule ^blog$ "https\:\/\/www\.lifeworks\.life\/blog\.html" [R=301,L]
Redirect 301 / http://lifeworks.life/
# FAILED ATTEMPTS AT WILDCARD REDIRECT
#RewriteCond %{HTTP_HOST} ^lifeworkslearningcenter\.com$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.lifeworkslearningcenter\.com$
#RewriteRule ^$ "https\:\/\/www\.lifeworks\.life\/index\.html" [R=301,L]
#RedirectMatch 301 /(.*) /$1
#RedirectMatch ^/(.*)$ http://lifeworks.life/$1
答案 0 :(得分:3)
您的通配符重定向应如下所示,并放在其他规则的底部。
RewriteRule ^(.*)$ https://www.lifeworks.life/$1 [R=301,L]
如果您需要根据未找到的文件重定向(404),您可以拥有这些规则。并将这些放在规则的底部。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://www.lifeworks.life/$1 [R=301,L]