【问题标题】:Issue with subdomains and htaccess for SEO用于 SEO 的子域和 htaccess 问题
【发布时间】:2013-01-17 11:22:43
【问题描述】:

我想将网址从:
http://subdomain.domain.com/page/ 更改为 http://subdomain.domain.com/?page=pagename
还有:
http://domain.com/page/http://domain.com/?page=pagename
虽然没有取得太大的成功。

这是我目前的 htaccess 文件 [已更新]

Options +FollowSymlinks -MultiViews

RewriteEngine On
RewriteBase /

# Remove 'www'
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://resolutiongaming.com/$1/ [L,R=301]

# Subdomain redirect
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]

# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1

我使用了RewriteRule ^([a-zA-Z]+)/$ ?page=$1,它似乎适用于域 url,但不适用于子域。任何帮助将不胜感激。

【问题讨论】:

    标签: .htaccess url mod-rewrite seo subdomain


    【解决方案1】:

    实际上最近不得不做这样的事情。为您的 子域重定向 块试试这个:

      RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$2 [R=301,L]
      RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$2 [R=301,L]
      RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$2 [R=301,L]
    

    或者也许这个;注意从 $2$1 的变化:

      RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
      RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
      RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
    

    编辑: 或者试试这个。请注意,您需要捕获 URL 的两个部分以在解释时重写。括号中的每一项 () 对应于重写中的一个字符串。尝试这个。使用您在 cmets 中提到的更好的正则表达式 RewriteRule

      RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/$2 [R=301,L]
    

    或者这样:

      RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/page=$2 [R=301,L]
    

    【讨论】:

    • 啊,我明白我为什么需要它了。但这并不能解决 RewriteRule ^([a-zA-Z]+)/$ ?page=$1 似乎不适用于子域的事实。
    • 我的意思是它会将http://resolutiongaming.com/webdev/page/ 更改为http://webdev.resolutiongaming.com/page/,这是我希望它执行的操作,但该网址不会更改为http://webdev.resolutiongaming.com/?page=page
    【解决方案2】:

    所以这真的很容易解决。我基本上在每个子域目录中放置了一个 .htaccess 文件,如下所示:

    Options +FollowSymlinks -MultiViews
    
    RewriteEngine On
    RewriteBase /
    
    # Search engine optimization
    RewriteRule ([a-zA-Z]+)/$ ?page=$1
    

    希望这对某人有所帮助。 :D

    【讨论】:

      猜你喜欢
      • 2013-03-23
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      相关资源
      最近更新 更多