.htaccess从html重定向到wordpress

.htaccess从html重定向到wordpress,wordpress,.htaccess,mod-rewrite,redirect,rewrite,Wordpress,.htaccess,Mod Rewrite,Redirect,Rewrite,我已经将一个站点从htm移动到Wordpress。我的重定向有问题。它们解析为“旧url”和“post”区域内的404。我已经尝试了重写和重定向,结果没有任何差异——代码显示了两种尝试过的变体 # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Redirect 301 rules here RewriteRule ^/Costa-Rica-Real-Estate\.htm$

我已经将一个站点从htm移动到Wordpress。我的重定向有问题。它们解析为“旧url”和“post”区域内的404。我已经尝试了重写和重定向,结果没有任何差异——代码显示了两种尝试过的变体

    # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Redirect 301 rules here
RewriteRule ^/Costa-Rica-Real-Estate\.htm$ http://www.sitename.com/costa-rica-property/ [L,R=301,NC] 
RewriteRule ^/costa-rica-videos\.htm$ http://sitename.com/costa-rica-videos/ [L,R=301,NC] 
redirect 301 /image-viewer.htm http://sitename.com/san-ramon-costa-rica-property-gallery/
redirect 301 /about.htm http://sitename.com/about/
#End redirect rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#开始WordPress
重新启动发动机
重写基/
#在这里重定向301规则
重写规则^/Costa Rica Real Estate\.htm美元http://www.sitename.com/costa-rica-property/ [L,R=301,NC]
重写规则^/costa rica videos\.htm$http://sitename.com/costa-rica-videos/ [L,R=301,NC]
重定向301/image-viewer.htmhttp://sitename.com/san-ramon-costa-rica-property-gallery/
重定向301/about.htmhttp://sitename.com/about/
#结束重定向规则
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

您需要从规则的正则表达式中删除前导斜杠,并且不要使用mod_别名(重定向指令)


重新启动发动机
重写基/
#在这里重定向301规则
重写规则^Costa Rica Real Estate\.htm$http://www.sitename.com/costa-rica-property/ [L,R=301,NC]
重写规则^costa rica videos\.htm$http://sitename.com/costa-rica-videos/ [L,R=301,NC]
重写规则^image viewer\.htm$http://sitename.com/san-ramon-costa-rica-property-gallery/ [L,R=301]
重写规则^about\.htm$http://sitename.com/about/ [L,R=301]
#结束重定向规则
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

第一个原因是,当规则位于htaccess文件中时,在应用规则之前,会从URI中删除前导斜杠,因此您的规则永远不会匹配。第二个原因是mod_alias和mod_rewrite都会应用到请求中,因此它们最终会相互干扰。

感谢Jon的帮助-仍然没有更改浏览器。我已经复制了您的代码,例如[link]RewriteRule^如何在哥斯达黎加购买房地产。htm$[L,R=301]更进一步-该代码在Hostgator网站上有效,但在GoDaddy网站上无效。谢谢你的帮助,乔恩
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Redirect 301 rules here
RewriteRule ^Costa-Rica-Real-Estate\.htm$ http://www.sitename.com/costa-rica-property/ [L,R=301,NC] 
RewriteRule ^costa-rica-videos\.htm$ http://sitename.com/costa-rica-videos/ [L,R=301,NC] 
RewriteRule ^image-viewer\.htm$ http://sitename.com/san-ramon-costa-rica-property-gallery/ [L,R=301]
RewriteRule ^about\.htm$ http://sitename.com/about/ [L,R=301]
#End redirect rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>