2016-08-22 6 views
2

У меня проблема с перенаправлением с htaccess. Мне нужно перенаправить 3 разных пути на 3 разных страницы, где у меня есть статические страницы, если пользователь является искателем.Перенаправление с htaccess не работает

Пример:

  • www.example.com -> www.example.com/static/index.php
  • www.example.com/news -> www.example.com/static/ news.php
  • www.example.com/home -> www.example.com/static/home.php

Я попробовал следующую конфигурацию, но я думаю, что есть какие-то правила в конфликте, на самом деле Я все еще перенаправлен на службу prerender.

<IfModule mod_rewrite.c> 
    Options +FollowSymlinks 
    RewriteEngine On 

    RewriteRule ^static - [L,NC] 

    RewriteCond %{HTTP_USER_AGENT} bot|crawl|slurp|spider|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|bingbot|Baiduspider|Yahoo|YahooSeeker|quora\ link\ preview|showyoubot|outbrain|pinterest|applebot [NC,OR] 
    RewriteCond %{REQUEST_URI} ^/home$ 
    # Proxy the request  
    RewriteRule ^/home /static/home.php [L] 

    RewriteCond %{HTTP_USER_AGENT} bot|crawl|slurp|spider|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|bingbot|Baiduspider|Yahoo|YahooSeeker|quora\ link\ preview|showyoubot|outbrain|pinterest|applebot [NC,OR] 
    RewriteCond %{REQUEST_URI} ^/news$ 
    # Proxy the request  
    RewriteRule ^/news /static/news.php [L] 

    RewriteCond %{HTTP_USER_AGENT} bot|crawl|slurp|spider|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|bingbot|Baiduspider|Yahoo|YahooSeeker|quora\ link\ preview|showyoubot|outbrain|pinterest|applebot [NC,OR] 
    RewriteCond %{REQUEST_URI} ^/$ 
    # Proxy the request  
    RewriteRule ^/$ /static/index.php [L] 

    # Handle Prerender.io 
    RequestHeader set X-Prerender-Token "------------------" 
    RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|bingbot|Baiduspider|Yahoo|YahooSeeker|quora\ link\ preview|showyoubot|outbrain|pinterest|applebot [NC,OR] 
    RewriteCond %{QUERY_STRING} _escaped_fragment_ 
    # Proxy the request 
    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))(.*) http://service.prerender.io/http://%{HTTP_HOST}/$2 [L] 


    # (REQUEST_FILENAME is only relative in virtualhost context, so not usable) 
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] 
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d 
    # Go to it as is 
    RewriteRule^- [L] 

    # If path ends with/and is not just a single /, redirect to without the trailing/
    RewriteCond %{REQUEST_URI} ^.*/$ 
    RewriteCond %{REQUEST_URI} !^/$ 
    RewriteRule ^(.*)/$ $1 [R,QSA,L] 

    # Accept everything on index.html 
    RewriteRule^index.html [L] 
</IfModule> 

Я изменил мой агент пользователя правильно с Google Chrome, но я до сих пор перенаправлен на пререндер службы.

+0

Удалить ведущие косые из шаблонов, например, 'RewriteRule^домой /static/home.php [L]' –

+1

... в в-справочник .htaccess файлы, 'RewriteRule' _pattern_ сопоставляется с URL-адресом, а не с префиксом каталога (где находится файл .htaccess) - поэтому он никогда не начинается с косой черты. – MrWhite

ответ

2

Имейте это так:

Options +FollowSymlinks 
RewriteEngine On 

RewriteCond %{HTTP_USER_AGENT} bot|crawl|slurp|spider|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|bingbot|Baiduspider|Yahoo|YahooSeeker|quora\ link\ preview|showyoubot|outbrain|pinterest|applebot [NC] 
# Proxy the request  
RewriteRule ^(home|news)(/.*)?$ /static/$1.php [L,NC] 

RewriteCond %{HTTP_USER_AGENT} bot|crawl|slurp|spider|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|bingbot|Baiduspider|Yahoo|YahooSeeker|quora\ link\ preview|showyoubot|outbrain|pinterest|applebot [NC,OR] 
# Proxy the request  
RewriteRule ^/?$ /static/index.php [L] 

# If path ends with/and is not just a single /, redirect to without the trailing/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/$ /$1 [NE,R=302,L] 

# Handle Prerender.io 
RequestHeader set X-Prerender-Token "------------------" 
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|bingbot|Baiduspider|Yahoo|YahooSeeker|quora\ link\ preview|showyoubot|outbrain|pinterest|applebot [NC,OR] 
RewriteCond %{QUERY_STRING} _escaped_fragment_ 
# Proxy the request 
RewriteRule ^(?!.*?\.(js|css|xml|less|png|jpe?g|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpe?g||tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff))(.*) http://service.prerender.io/http://%{HTTP_HOST}/$2 [L] 

# (REQUEST_FILENAME is only relative in virtualhost context, so not usable) 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d 
# Go to it as is 
RewriteRule^- [L] 

# Accept everything on index.html 
RewriteRule^index.html [L] 
+1

спасибо! все работает. – StarsSky

Смежные вопросы