为子目录URL预渲染htaccess

时间:2019-04-21 13:54:21

标签: apache .htaccess prerender

这是我的htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]

RequestHeader set X-Prerender-Token "**************"

<IfModule mod_rewrite.c>

    <IfModule mod_proxy_http.c>
        RewriteCond %{HTTP_USER_AGENT} googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
        RewriteCond %{QUERY_STRING} _escaped_fragment_

        # Proxy the request
        RewriteRule ^(.*)$ http://service.prerender.io/http://%{HTTP_HOST}$1 [P,L]


        RewriteRule ^ /index.html 
    </IfModule>
</IfModule>

我已经在Angularjs中完成了这些操作-

<head>
    <meta name="fragment" content="!">
</head>

$locationProvider.html5Mode(true);

我的网址看起来像-

https://www.{Hostname}/{folder-name}/ (BaseURl)

当我在url下方关注时,它将在404上重定向我

https://www.{Hostname}/{folder-name}/category/category-name

有人可以帮助我解决htaccess问题吗?

1 个答案:

答案 0 :(得分:-1)

您将需要确保Prerender配置在.htaccess的此部分之前运行:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]

您的.htaccess文件可能如下所示:

RewriteEngine On

RequestHeader set X-Prerender-Token "**************"

<IfModule mod_rewrite.c>

    <IfModule mod_proxy_http.c>
        RewriteCond %{HTTP_USER_AGENT} googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
        RewriteCond %{QUERY_STRING} _escaped_fragment_

        # Only proxy the request to Prerender if it's a request for HTML
        RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff|\.svg))(.*) http://service.prerender.io/https://%{HTTP_HOST}.com/$2 [P,L]
    </IfModule>
</IfModule>

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]

如果这不能解决问题,请随时通过support@prerender.io向我们发送电子邮件,并提供更多信息,以便我们提供帮助!