2011-07-31 1 views
2

サブディレクトリからTumblrのブログを実行するために小さなプロキシで作業していました。私はexample.com/blog/にTumblogを隠すことができましたが、私はブログのリンクのいずれにも従うことができません。私はデザイナーで、これを研究している日の良い部分を過ごしました。これはあなたにすべて愚かに聞こえる場合は申し訳ありません。私の質問は、なぜブログのリンクが機能していないのですか?サブディレクトリ上でTumblrをほぼ成功させる

は、ここに私の.htaccessです:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^blog\/?$ proxy.php?url=http://seo-services-greece.tumblr.com/$1?% 

<IfModule mod_expires.c> 
    ExpiresActive on 
    ExpiresByType image/gif A2592000 
    ExpiresByType image/jpeg A2592000 
    ExpiresByType image/png A2592000 
    ExpiresByType text/css A2592000 
    ExpiresByType application/javascript A2592000 
    #ExpiresDefault A2592000 
</IfModule> 

AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/xml 
AddOutputFilterByType DEFLATE application/xhtml+xml 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE application/xml 
AddOutputFilterByType DEFLATE image/svg+xml 
AddOutputFilterByType DEFLATE application/rss+xml 
AddOutputFilterByType DEFLATE application/atom_xml 
AddOutputFilterByType DEFLATE application/x-javascript 
AddOutputFilterByType DEFLATE application/x-httpd-php 
AddOutputFilterByType DEFLATE application/x-httpd-fastphp 
AddOutputFilterByType DEFLATE application/x-httpd-eruby 
AddOutputFilterByType DEFLATE text/html 
AddOutputFilterByType DEFLATE text/javascript 
AddOutputFilterByType DEFLATE application/javascript 
AddOutputFilterByType DEFLATE text/ecmascript 
AddOutputFilterByType DEFLATE application/ecmascript 
AddOutputFilterByType DEFLATE text/jscript 

Header unset ETag 
FileETag None 

Options +FollowSymlinks 
RewriteEngine on 
rewritecond %{http_host} ^seoprojects.gr [nc] 
rewriterule ^(.*)$ http://www.seoprojects.gr/$1 [r=301,nc] 

はここに私のproxy.phpです:

<?php 

$from = "seo-services-greece.tumblr.com"; 
$unto = "seoprojects.gr/blog"; 

// Because Dreamhost doesn't do remote fopens, and to get content-type 
function fetch($url) { 
    $curl = curl_init(); 
    $timeout = 5; // set to zero for no timeout 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
    $html = curl_exec($curl); 
    $content_type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); 
    curl_close($curl); 
    return array($html, $content_type); 
} 

list($html, $content_type) = fetch($_GET['url']); 

// Fix root-relative links etc. 
$html = preg_replace('/\b(href|src|rel)="\//', '$1="http://'.$unto.'/', $html); 

// Fix the iframe-url 
$html = str_replace("iframe?src=http://".$unto, "iframe?src=http://".$from, $html); 

// fix audioplayer-url 
$html = str_replace("audio_file=http://".$unto, "audio_file=http://".$from, $html); 

// Replace the old URL with the new 
$html = str_replace($from, $unto, $html); 

header("Content-type: $content_type"); 
echo $html; 

?> 
+0

この規則:?あなたはヨーヨー非常に上から下から、それらを移動し、それらに前proxy.phpルールを配置する必要がありますか? 'のRewriteRule ^ブログ\/$のproxy.phpをURL =のhttp:// seo-services-greece.tumblr.com/$1?% ' - 私は' $ 1'の出所がないと思っています。動作していないURLの1つまたは2つの例(および動作するURL)を入力してください。 – LazyOne

+0

たとえば、http://www.seoprojects.gr/blogは動作しますが、http://seoprojects.gr/blog/post/8269828437/testの結果は404. –

+0

@user871896です。1)あなたがJacob Warren同じアカウントを使用してください。代わりに誰かに返信するのは変です。 2)あなたのコメントを投稿するのにANSWERを使用しないでください - 代わりに「コメント」機能を使用してください。 – LazyOne

答えて

1

あなたの書き換えルール(パターン)が間違っている - あなたが戻って$1を参照していますが、 $1に使用される「キャッチグループ」はありません。代わりに、これらの行を使用します。第二は/blog/somethingで動作する一方

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^blog/?$ proxy.php?url=http://seo-services-greece.tumblr.com/ [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^blog/(.+)$ proxy.php?url=http://seo-services-greece.tumblr.com/$1 [L] 

最初のルールが/blog/blog/に対処します。

残念ながら、クエリ文字列はすべて失われます(例:/blog/?ref=yahoo)。 proxy.phpにも渡すには、ターゲットURLの末尾に?%{QUERY_STRING}を追加してください。 proxy.php?url=http://seo-services-greece.tumblr.com/$1?%{QUERY_STRING} - ちょうどそのように動作することを保証するものではありません。エスケープする必要があるかもしれません。


UPDATE: あなたは2つの書き換えルールブロックがある - 非常に上部の1と.htaccessの一番最後に1つを。

Options +FollowSymlinks 
RewriteEngine On 
RewriteBase/

# force www. in domain name 
RewriteCond %{HTTP_HOST} ^seoprojects.gr [NC] 
RewriteRule ^(.*)$ http://www.seoprojects.gr/$1 [R=301,L] 

# thumblr proxy rules 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^blog/?$ proxy.php?url=http://seo-services-greece.tumblr.com/ [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^blog/(.+)$ proxy.php?url=http://seo-services-greece.tumblr.com/$1 [L] 
関連する問題