Codeigniter url使用.htaccess重写为子域名url

时间:2012-07-19 10:01:33

标签: .htaccess

1 个答案:

答案 0 :(得分:1)

将.htaccess文件放入http://www.domain.co.uk/ document root

致http://www.city-name.domain.co.uk/index.php/city/details/city-name

RewriteRule ^(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]

致http://www.city-name.domain.co.uk/index.php/city/details/city-name

RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L] 

如果服务器相同,请在此行上方设置RewriteRule以防止重定向循环

RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]  

文件内容示例

<ifModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]  
   RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]  
</IfModule>

排除domain.co.uk(whitout www)

<ifModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_HOST} !^www\.(.*).domain\.co\.uk [NC]
   RewriteCond %{HTTP_HOST} !^domain\.co\.uk [NC]  
   RewriteRule ^index.php/(.*)/([^/]+)$ http://www.$2.domain.co.uk/$1/$2 [R=301,L]     
</IfModule>