简体   繁体   English

将404重定向到搜索页面

[英]Redirect 404 to search page

Becouse in google webmasters I have 550.000 not found pages - 404 - I want to make some redirections to the search page. 因为在Google网站管理员中,我有550.000个未找到的页面-404-我想对搜索页面进行一些重定向。

To be userfoul for the users, need to go to the search page, but is realy complicated for me, becouse I need to EXTRACT the search phrase from the 404 url: 要成为用户的用户犯规,需要进入搜索页面,但是对我来说确实很复杂,因为我需要从404网址中提取搜索词组:

Here are the 2 type of url with 404 errors, and need to be redirected. 这是2种类型的404错误网址,需要重定向。

  • DOMAIN/movie/12298295-Iron-Man-3 DOMAIN / movie / 12298295-Iron-Man-3

    DOMAIN/serie/15108-The-Walking-Dead/seasons/3/episodes/10 DOMAIN / serie / 15108-步行中的死亡/赛季/ 3 /情节/ 10

Of corse, I need to extract JUST THE NAME of the movie, or the serie and redirect to this url 言归正传,我需要提取电影的名称或意甲,然后重定向到该网址

  • DOMAIN/search?q=Iron-Man-3 DOMAIN / search?q =钢铁侠3

    DOMAIN/search?q=The-Walking-Dead DOMAIN / search?q =行尸走肉


Well this is the URL by parts: For "movies" just have 4 parts: 嗯,这是URL的组成部分:“电影”只有4个部分:

  • DOMAIN - of corse, is the domain name of the website DOMAIN-corse,是网站的域名

    /movie/ - is created based on the content type (movie or serie) / movie /-根据内容类型(电影或系列)创建

    12298295- is the ID for this item and can be form - 1 - to infinite 12298295-是此项的ID,可以是-1-无限

    Iron-Man-3 - the name of the movie (is wath I want to get) 钢铁侠3-电影的名字(我想得到的是什么)

For "series" - THE SAME like for the movies, but at the end can have more parts, and the full URL can be: (all this url, for an normal page with NO 404, are ok) 对于“系列”-就像电影一样,但最后可以包含更多部分,并且完整的URL可以是:(对于没有404的正常页面,所有这些URL都可以)

  • DOMAIN/serie/15108-The-Walking-Dead/seasons/3/episodes/10 - Link to episode page DOMAIN / serie / 15108-The-Walking-Dead / seasons / 3 / episodes / 10-链接至剧集页面

    DOMAIN/serie/15108-The-Walking-Dead/seasons/3/ - Link to some season page DOMAIN / serie / 15108-步行中的死亡/季节/ 3 /-链接到某些季节页面

    DOMAIN/serie/15108-The-Walking-Dead/ - Link to the TOP page for this serie DOMAIN / serie / 15108-The-Walking-Dead /-链接到该系列的TOP页面


Please note, I need to redirect this url, JUST if the result is an 404 page (ErrorDocument 404), becouse the same type of url are used in all pages. 请注意,我需要重定向此url,只是如果结果是404页面(ErrorDocument 404),因为所有页面中都使用了相同类型的url。

Here is my actual .htacces 这是我实际的.htacces

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=301,NC,NE]

    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=301,NC,NE]

    RewriteCond %{QUERY_STRING} ^q= [NC]
    RewriteRule ^busqueda\b /busquedas [R=301,L,QSA]

    # Redirect Trailing Slashes...
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Many thanks for your help 非常感谢您的帮助

以下内容适用于电影和电视连续剧:

RewriteRule ^(?:movie|serie)/\d+-([^/]+) /search?q=$1 [R=301,L,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM