【问题标题】:Redirect Subdomain to a specific page将子域重定向到特定页面
【发布时间】:2015-03-02 06:45:29
【问题描述】:

我正在尝试将http://pk.domain.com 重定向到http://www.domain.com/home.php?country=pk,同样将http://www.domain.com/pk/ 重定向到http://www.domain.com/home.php?country=pk

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]

RewriteRule ^([^/]+)/?$ adlisting.php?country=%1&category=$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]

RewriteRule ^([^/]+)/([^/]+)/?$ adlisting.php?country=%1&location=$1&category=$2 [L,QSA]

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]

RewriteRule ^([a-z]{2})/([^/]+)/?$ adlisting.php?country=$1&category=$2 [L,QSA,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]

RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ adlisting.php?country=$1&location=$2&category=$3 [L,QSA,NC]

这个问题链接到Multi-Country Using .htacces

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    在其他规则之前添加2条登陆页面规则:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
    RewriteRule ^/?$ home.php?country=%1 [L,QSA]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteRule ^([a-z]{2})/?$ home.php?country=$1 [L,QSA,NC]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
    RewriteRule ^([^/]+)/?$ adlisting.php?country=%1&category=$1 [L,QSA]
    
    RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
    RewriteRule ^([^/]+)/([^/]+)/?$ adlisting.php?country=%1&location=$1&category=$2 [L,QSA]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteRule ^([a-z]{2})/([^/]+)/?$ adlisting.php?country=$1&category=$2 [L,QSA,NC]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ adlisting.php?country=$1&location=$2&category=$3 [L,QSA,NC]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2021-08-08
      • 2010-12-06
      • 1970-01-01
      • 2016-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多