问题描述
我有它的故事一个网站。我可以有多个类型的多个类别中的故事一样的:
I have a website with stories in it. I can have multiple types of stories within multiple categories like:
- 孩子
- 爱情
- 在科幻
- 动作
- thriler
- 任务
的故事是通过URL访问,如:
The stories are accessible using urls like:
www.example.com/action/story-name-action/
www.example.com/romance/story-name-romance/
和所述第一个参数(动作)和第二(故事名称作用)重定向使用规则htaccess的。 这部分工作得很好。的
and the first param (action) and the second (story-name-action) are redirected with .htaccess using rules. This part works just fine.
最近,我得到的404从不同的站点几十这里就是我想要做的,但我不知道如何:
Lately, I get few dozen of 404 from different sites and here's what I want to do but I dont know how:
如果有人类型,例如: /动作/剧情-NME-ction
,我要重定向到:动作/剧情-名 - 动作/
If someone types, for example: /action/story-nme-ction
, I want to redirect to: action/story-name-action/
有没有实现这样的一个有效的方法?
Is there an efficient way to implement this?
推荐答案
哦,哦,天哪!
什么你问的不是简单的,需要你有一个强大的计算机,但结果简直太神奇了。
What you're asking for is not simple and need you to have a powerful computer, but the results are simply amazing.
下面就是我建议这样做:
Here's what I'd suggest to do:
- 404妥善处理,你有
的ErrorDocument
重定向在虚拟主机的配置。我的是这样:的ErrorDocument 404 /404.php
; - 在具有404时,Apache会调用
/404.php
的所有参数(这糟糕的URL等,倾倒$ _ SERVER
看到这一点)。你要测试是否只有两个EX pressions在网址/
即http://mysite.com/(表达式1)/ (表达式2)/
- 如果不是,然后做一个经典的404。
- 如果是的话那么做 SOUNDEX 与MySQL查询(在
404腓
文件)。请参阅查询样品这里。 - 然后,在这个特殊404的情况下,做一个建议,像谷歌那样,如:你的意思是
/动作/剧情名动/
?如果是的话,请点击链接上。
- For 404 proper handling, you have the
ErrorDocument
redirection in vhost configuration. Mine looks like this:ErrorDocument 404 /404.php
; - When having a 404, Apache will call
/404.php
with all the arguments (which bad URL and so on, dump$_SERVER
to see this). You have to test if there are only two expressions in the URL/
i.e.http://mysite.com/(expr1)/(expr2)/
- If not, then do a classical 404.
- If yes then do a SOUNDEX search with MySQL (in your
404 Php
file). See query sample here. - Then, in this "special" 404 case, do a suggestion, like google does, i.e.: "did you mean
/action/story-name-action/
? if so, click on the link".
这是一个艰苦的工作,但它是既有趣又显示你的技能。只有极少数的网站做到这一点(我只知道谷歌其实)。
This a hard work, but it's both interesting and shows your skill. Very few websites do this (I just know google actually).
下面是我的法语表中的演示,可以给你它是如何工作的概述:
Here's a demo on my French table that could give you an overview of how it works:
mysql> SELECT * FROM job WHERE
SOUNDEX( description ) LIKE SOUNDEX('Machiniste cinéma');
+-------+--------------------+
| id | description |
+-------+--------------------+
| 14018 | Machiniste cinéma |
+-------+--------------------+
1 row in set (0.06 sec)
mysql> SELECT * FROM job WHERE
SOUNDEX( description ) LIKE SOUNDEX('Mchiniste cinéma');
+-------+--------------------+
| id | description |
+-------+--------------------+
| 14018 | Machiniste cinéma |
+-------+--------------------+
1 row in set (0.06 sec)
mysql> SELECT * FROM job WHERE
SOUNDEX( description ) LIKE SOUNDEX('Machnste cinema');
+-------+--------------------+
| id | description |
+-------+--------------------+
| 14018 | Machiniste cinéma |
+-------+--------------------+
1 row in set (0.06 sec)
mysql>
这篇关于404重定向到类似的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!