WDCP利用.htaccess文件设置301重定向方法

前端之家收集整理的这篇文章主要介绍了WDCP利用.htaccess文件设置301重定向方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前面的中我们已经介绍了

本站运行在阿里云ECS上,使用的是管理面板。在wdcp控制面板中可以设置301重定向,但是操作步骤稍微有点繁琐,需要创建两个站点,第一个为网站文件(绑定主域名),第二个(绑定要做301的域名)直接设置301重定向连接到第一个站点就可以了。

这篇教程里我们介绍一下WDCP利用.htaccess文件设置301重定向方法。使用WDCP管理面板的站长会发现,直接将以下代码放入到.htaccess文件中,并不能成功实现301重定向

Crayon-5c891ce8d06f2352255674" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">.htaccess
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891ce8d06f2352255674-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce8d06f2352255674-2">2
Crayon-num" data-line="Crayon-5c891ce8d06f2352255674-3">3
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891ce8d06f2352255674-1">Crayon-e">RewriteEngineCrayon-h"> Crayon-e">On
Crayon-line Crayon-striped-line" id="Crayon-5c891ce8d06f2352255674-2">Crayon-e">RewriteCondCrayon-h"> Crayon-o">%Crayon-sy">{Crayon-v">http_hostCrayon-sy">}Crayon-h"> Crayon-o">^Crayon-cn">91wordpress.comCrayon-sy">$Crayon-h"> Crayon-sy">[Crayon-v">NCCrayon-sy">]
Crayon-line" id="Crayon-5c891ce8d06f2352255674-3">Crayon-v">RewriteRuleCrayon-h"> Crayon-o">^Crayon-sy">(Crayon-sy">.Crayon-o">*Crayon-sy">)Crayon-sy">$Crayon-h"> Crayon-v">httpsCrayon-o">:Crayon-c">//www.91wordpress.com/$1 [R=301,L]

原因是少了IfModule配置段,在WDCP需要增加IfModule配置段,.htaccess设置301重定向才能成功。下面附上完整的301重定向代码

Crayon-5c891ce8d06fa872888441" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">.htaccess
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891ce8d06fa872888441-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce8d06fa872888441-2">2
Crayon-num" data-line="Crayon-5c891ce8d06fa872888441-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce8d06fa872888441-4">4
Crayon-num" data-line="Crayon-5c891ce8d06fa872888441-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce8d06fa872888441-6">6
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891ce8d06fa872888441-1">Crayon-o"><Crayon-e">IfModule Crayon-v">mod_rewriteCrayon-sy">.Crayon-v">c
Crayon-line Crayon-striped-line" id="Crayon-5c891ce8d06fa872888441-2">Crayon-e">RewriteEngineCrayon-h"> Crayon-e">On
Crayon-line" id="Crayon-5c891ce8d06fa872888441-3">Crayon-e">RewriteBaseCrayon-h"> Crayon-o">/
Crayon-line Crayon-striped-line" id="Crayon-5c891ce8d06fa872888441-4">Crayon-e">RewriteCondCrayon-h"> Crayon-o">%Crayon-sy">{Crayon-v">http_hostCrayon-sy">}Crayon-h"> Crayon-o">^Crayon-cn">91wordpress.comCrayon-sy">$Crayon-h"> Crayon-sy">[Crayon-v">NCCrayon-sy">]
Crayon-line" id="Crayon-5c891ce8d06fa872888441-5">Crayon-v">RewriteRuleCrayon-h"> Crayon-o">^Crayon-sy">(Crayon-sy">.Crayon-o">*Crayon-sy">)Crayon-sy">$Crayon-h"> Crayon-v">httpsCrayon-o">:Crayon-c">//www.91wordpress.com/$1 [R=301,L]
Crayon-line Crayon-striped-line" id="Crayon-5c891ce8d06fa872888441-6">Crayon-o"><Crayon-o">/Crayon-v">IfModule

希望这篇教程可以帮助到有相似经历的站长们。

猜你在找的wordpress相关文章