的.htaccessmod-rewrite正则表达式的Apache的混乱导致了10K 404的每天 [英] .htaccess mod-rewrite regex apache confusion results in 10k 404's per day

查看:339
本文介绍了的.htaccessmod-rewrite正则表达式的Apache的混乱导致了10K 404的每天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经审查张贴在这里与的.htaccess 的许多问题阿帕奇mod-rewrite正则表达式,但我只是没有得到它。我尝试了一些不同的东西,但无论我是在复杂的事物或使初学者的错误。无论如何,我现在已经在这几天,已经完全炒东西的地方为10000 404的,每天都出现。

I have reviewed the many questions posted here related to .htaccess, apache, mod-rewrite and regex, but I'm just not getting it. I tried a few different things but either I am over complicating things or making beginner mistakes. Regardless, I've been at it a few days now and have completely scrambled things somewhere as the 10000 404's per day are showing.

我的网站

我有一个字preSS网站,其中包含超过23000职位细分为刚刚超过1200范畴。该网站设有流媒体视频文件,行业新闻,评论节目,电影,phpBB论坛等,其结构是这样的:

I have a WordPress site which contains over 23,000 posts broken down into just over 1200 categories. The site features streaming video files, industry news, show reviews, movies, phpbb forums, etc. and is structured like this:

  • 在网站/基础类(0和AZ)/子类别(系列名)/ 帖子(集名称的.html)的所有流媒体集
  • 在网站/电影/后title.html所有流媒体电影
  • 在网站/新闻/ posttitle.html
  • 在网站/评论/ posttitle.html
  • 在网站/ page.html即可用于各类页
  • 在网站/论坛
  • site / base categories ( 0 and a-z) / sub categories (series name) / posts (episode name .html )for all streaming media episodes
  • site / movies / post title.html for all streaming movies
  • site / news / posttitle.html
  • site / reviews / posttitle.html
  • site / page.html for assorted pages
  • site / forums

永久链接结构是 /%类别%/%postname%的.html

我现在用的是Yoast字preSS SEO插件,并有附加启用目录和类别斜线的选项。

I have am using the Yoast Wordpress SEO plugin and have the option to append a trailing slash enabled for directories and categories.

下面是电流的.htaccess

    # 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

我的例子

这是我们的老网站结构,我们必须使用/插曲标题/很多的内部链接。这是错误的。我们需要这些接踵而来的链接重定向到/手表动漫/字母,数字或符号只有1个字符长/系列标题/插曲title.html

From our old site structure we have many inbound links using "/episode title/". This is wrong. We need these incoming links to redirect to /watch-anime/letter, number or symbol only 1 character long/series title/episode title.html

/one-piece-episode-528​/

/watch-anime/o/one-piece/​one-piece-episode-528​.html

我犯了导致此问题的一个错误...... /手表动漫/信/系列标题/插曲标题/ /观看动画视频/信/系列标题/插曲title.html 。因此,我们需要从单一的帖子删除斜线和添加的.html

A mistake I made caused this problem... "/watch-anime/letter/series title/episode title/" to "/watch-anime/letter/series title/episode title.html". So, we need to remove trailing slash from single posts and add .html

/watch-anime​/w​/welcome-to-the-nhk​/welcome-to-the-nhk-episode-14​/

/watch-anime​/w​/welcome-to-the-nhk​/welcome-to-the-nhk-episode-14​.html

同样的错误导致此问题,当与旧网站的结构问题相结合...... /插曲title.html 需要 /观看动画视频/信/系列标题/插曲title.html

/one-piece-episode-528​.html

必须是

/watch-anime/o/one-piece/​one-piece-episode-528​.html

正如你所看到的,我已经迁移站点张贴结构,我试图修复它之间进行乱七八糟的东西。我现在问任何帮助,您可以进行正确的.htaccess文件,将采取这些301重定向的护理提供。

As you can see, I've made a mess of things between migrating the sites post structure and my attempts to fix it. I am now asking for any help you can provide in getting a proper .htaccess file that will take care of these 301 redirects.

感谢任何可以提供帮助!

Thanks for any assistance you can provide!

推荐答案

我不知道是否与的.htaccess 文件RewriteMap指令的工作,但无论如何,这是我的虚拟化解决方案主机,它应该工作得很好。

I don't know if RewriteMap work with .htaccess files, but anyway here's my solution for virtual host, which should work flawlessly.

创建 RewriteMap指令文件。请参见这里了解更多信息。这是一个非常简单的文本文件:第一,错误的URL的没有/的,然后点击有一个空格(至少),然后将正确的网址,例如:

Create a RewriteMap file. See here for more information. This is a very simple text file with: first, the wrong URL without the '/', then one space (at least) and then the right url, like this:

one-piece-episode-528​ /watch-anime/o/one-piece/​one-piece-episode-528​.html
dexter-season-6-episode-1 /watch-interesting-stuff/d/dexter/dexter-season-6-episode-1.html
breaking-bad-full-season-3 /watch-interesting-stuff/b/breaking-bad/​breaking-bad-full-season-3.html

等等。

转换这个简单的文本文件转换成散列映射。例如:

convert this simple text file into hash map. For example:

httxt2dbm -i mapanime.txt -o mapanime.map

现在在你的虚拟主机声明它:

Now declare it in your vhost:

RewriteMap mapanime \
    dbm:/pathtofile/mapanime.map

因此​​,所有的所有的虚拟主机应该是这样的:

So all in all your vhost should look like:

<VirtualHost *>
    RewriteEngine On
    RewriteMap mapanime \
        dbm:/pathtofile/mapanime.map
    # don't touch the URL, but try to search if it exists in mapanime
    RewriteRule /([^/]*)/$ - [QSA,NC,E=VARANIME:${mapanime:$1|notfound}]
    # if VARANIME not empty *and*
    #   VARANIME different from "notfound":
    RewriteCond %{ENV:VARANIME} ^(notfound|)$
    # then redirect it to the right URL:
    # QSA = query string append
    # R = redirect, 301 = definitive redirect
    # L = last = don't go further
    RewriteRule . %{ENV:VARANIME} [QSA,R=301,L]
</VirtualHost>

希望这有助于。

Hope this helps.

我不明白一个简单的解决方案,但我pretty的肯定,这人会工作。

I don't see a simpler solution, but I'm pretty sure this one will work.

如果它不工作:看我平时的两提示,并在你的问题中添加重写日志

If it doesn't work: read my usual "two hints", and add the rewrite log in your question.

请尝试使用 RewriteLog 指令:它可以帮助您追踪到这样的问题:

Please try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On


我最喜欢的工具来检查正则表达式:


My favorite tool to check for regexp:

http://www.quanetic.com/Regex ​​(不要忘记选择额日格( POSIX代替preG)(PCRE)!)

http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

这篇关于的.htaccessmod-rewrite正则表达式的Apache的混乱导致了10K 404的每天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆