2017-08-12 5 views
0

私は地元の学校のための小さな教育サイトを作っています。現在、サイトは開発とテストのためにサブドメインでホストされています。しかし、どういうわけかGoogleは自分のサイトをクロールすることができたので、トピックとウェブサイトの名前をGoogleで検索すると、結果にサブドメインが表示されます。ルートドメインにリダイレクトするHTACCESS

サイトをメインドメインに移動し、サブドメインにアクセスしているユーザーをメインドメインの対応するルートにリダイレクトします。

これは、サブドメインでRewriteRulesを含む.htaccessファイルです:

Options +FollowSymLinks 
RewriteEngine on 

RewriteRule ^log-in$ index.php?section=log-in [QSA] 
RewriteRule ^register$ index.php?section=register [QSA] 
RewriteRule ^courses$ index.php?section=courses [QSA] 
RewriteRule ^contact$ index.php?section=contact [QSA] 
RewriteRule ^instructor$ index.php?section=instructor [QSA] 
RewriteRule ^my-profile$ index.php?section=my-profile [QSA] 

RewriteRule ^404$ index.php?section=404 [QSA] 

RewriteRule ^course/([0-9]+)$ index.php?section=course&course_id=$1 [QSA] 
RewriteRule ^course/([0-9]+)/lecture-id/([0-9]+)$ index.php?section=course&course_id=$1&lecture_id=$2 [QSA] 

RewriteRule ^articles$ index.php?section=articles [QSA] 
RewriteRule ^articles/([a-zA-Z0-9\-]+)$ index.php?section=articles&article_category=$1 [QSA] 
RewriteRule ^article/([a-zA-Z0-9\-]+)$ index.php?section=article&slug=$1 [QSA] 

RewriteRule ^log-out$ res/php/user_actions/logout.php [QSA] 

したがって、これらは、私は基本的にリダイレクトする

sub.domain.com   => domain.com 
sub.domain.com/courses => domain.com/courses 
sub.domain.com/course/5 => domain.com/course/5 
sub.domain.com/articles => domain.com/articles 
sub.domain.com/article/article-name => domain.com/article/article-name 
and so on... 

を起こるはずリダイレクトのいくつかの例であり、ユーザーはメインルート上の同じルートに移動します。どのように私はこれを達成し、私のリダイレクションを適切に管理できるので、私のSEOランキングは傷つきませんか?理想的にはhtaccessファイルでリダイレクトを管理したいと考えています。

答えて

0

これを試してみてください:

RewriteCond %{HTTP_HOST} ^sub\.example\.com [NC] 
RewriteRule .* https://example.com%{REQUEST_URI} [R=301,L] 
+0

は、私は私のサブドメインののhtaccessファイルでこれを置く必要がありますか? –

+0

サブドメインを完全に削除し、サイトのメイン.htaccessファイルに投稿した内容を追加します。 サブドメインを保持する必要がある場合は、投稿したもの、またはRewriteRuleだけを貼り付けることができます.RewriteCondはサブドメインで常に満たされるためです。 –

+0

もう一度質問してください。私はRewriteRuleがドメイン名の前に 'https'を持っているのを見ています。もし私がSSL証明書を持っていなければ、プロトコルの 's'を除いて、' RewriteRule。* http://example.com% {REQUEST_URI} [R = 301、L] –

関連する問題