2012-01-23 13 views
0

http://example.com/links/AAAからhttp://links.example.net/l/AAAAAAは変数)へのリダイレクトを作成しようとしています。私はそれが働いている。問題は、http://example.com/links/http://example.com/linksの両方がhttp://links.example.net/l/なし)にリダイレクトされることです。.htaccessクロスドメインリダイレクト

http://example.com/links/http://links.example.net/l/にリダイレクトされ、example.com/linkshttp://links.example.net/l//hsphere/local/home/username/example.com/linksにリダイレクトされます。

現在.htaccess

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} (.+)$ [NC] 
    RewriteRule ^(.*)$ http://links.example.net/l/$1 [R=301,L] 
</IfModule> 

擬似コード:私はここに他の.htaccess質問の束に目を通してきた

if ($path) { 
    goto(http://links.example.net/l/${path}/); // Adding the trailing slash is not necessary, but would be handy. Obviously, don't add if it already exists. 
} else { 
    goto(http://links.example.net/); 
} 

(良い悲しみが非常に多くある)が、同等の何かを見つけるためには至っていません。

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)$ index.php/$1 
</IfModule> 

をそして、私は自宅でもう少しだPHPでリダイレクトを実行します。

必要であれば、私はこの別の方法を行うことができます。しかし、それは(a)効率が悪く、(b)楽しくなく、(c)教育が難しいということです。だから私はこれを正しい方法でやろうとしています。

答えて

2

ここでは、.htaccessファイルがサイトのルートディレクトリにあると仮定しています。

RewriteEngine on 
RewriteBase/

#if /links or links/ (path empty) 
RewriteCond %{REQUEST_URI} ^/links/?$ [NC] 
RewriteRule^http://links.example.net [R=301,L] 

#otherwise 
RewriteRule ^links/(.*)$ http://links.example.net/l/$1 [R=301,NC,L] 
+0

ありがとうございます。私は明日の朝にその最初のことを試し、あなたに報告します。 – TRiG