重定向301 .htaccess拼图

时间:2014-08-20 14:56:09

标签: .htaccess mod-rewrite redirect http-status-code-301

我正在网站 www.successfulspeakernow.com 上工作,该网站已从常规根 public_html 文件夹移至 public_html / successfulspeakernow文件夹.com

在新网站中有许多新网页,有些旧网页已被取消。 现在位于根文件夹 public_html 中的是 .htaccess 文件,其中包含以下内容:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^successfulspeakernow\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.successfulspeakernow\.com$
RewriteRule ^tedx\-amsterdam\-women$ "http\:\/\/www\.successfulspeakernow\.com\/category\/blog" [R=301,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^successfulspeakernow.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.successfulspeakernow.com$
RewriteCond %{REQUEST_URI} !successfulspeakernow.com/
RewriteRule (.*) /successfulspeakernow.com/$1 [L]
Redirect 301 http://www.successfulspeakernow.com/introducing-speaker-in-the-spotlight http://www.successfulspeakernow.com/category/blog

#SetEnv PHPRC /etc/php_succesfulspeaker.ini

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

然后在 public_html / successfulspeakernow.com 文件夹中有第二个 .htaccess 文件,其中包含以下内容:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /introducing-speaker-in-the-spotlight http://www.successfulspeakernow.com/category/blog
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


</IfModule>

# BEGIN MemberPress Rules
<IfModule mod_rewrite.c>

RewriteCond %{HTTP_COOKIE} mplk=([a-zA-Z0-9]+)
RewriteCond /home/succes96/public_html/successfulspeakernow.com/wp-content/uploads/mepr/rules/%1 -f
RewriteRule ^(.*)$ - [L]

RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-includes)
RewriteCond %{REQUEST_URI} !\.(txt|php|phtml|jpg|jpeg|gif|css|png|js|ico|svg|woff|ttf|xml|TXT|PHP|PHTML|JPG|JPEG|GIF|CSS|PNG|JS|ICO|SVG|WOFF|TTF|XML)
RewriteRule . /~succes96/successfulspeakernow.com/wp-content/plugins/memberpress/lock.php [L]

</IfModule>
# END MemberPress Rules

# END WordPress

正如您所看到的,我已经包含了一个Redirect 301系列。它似乎不起作用。当我在浏览器中输入: www.successfulspeakernow.com/introducing-speaker-in-the-spotlight 时,我没有被重定向到博客页面,但我得到了404.我的托管服务提供商( Siteground.com)无法找到这个问题,并建议通过cPanel重定向功能重定向此(和所有其他)URL。

如果我做错了什么,谁能告诉我?这应该有用,不应该吗?忘了一行代码? EHR ....?

Thanx,

汤姆 Thomsterdam

2 个答案:

答案 0 :(得分:0)

您需要使用mod_rewrite而不是mod_alias。 Redirect指令是mod_alias的一部分,两个模块都会处理一个URL,这意味着你的所有规则都会混乱,并最终弄乱相同的URL。

删除Redirect行并将其替换为:

RewriteRule /introducing-speaker-in-the-spotlight http://www.successfulspeakernow.com/category/blog [L,R=301]

答案 1 :(得分:0)

此响应仅用于说明您的配置无法正常工作的原因。 Jon Lin 解决方案应该有效。

代码无效,因为mod_rewrite优先:

这正在更改您请求的URI:

RewriteCond %{HTTP_HOST} ^successfulspeakernow.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.successfulspeakernow.com$
RewriteCond %{REQUEST_URI} !successfulspeakernow.com/
RewriteRule (.*) /successfulspeakernow.com/$1 [L]

www.successfulspeakernow.com/introducing-speaker-in-the-spotlight的请求在内部(mod_alias工作之前)转换为此www.successfulspeakernow.com/successfulspeakernow.com//introducing-speaker-in-the-spotlight

然后,重定向不适用,因为URL不匹配..