目前我的网址是:http://www.domain.co.uk/index.php/city/details/city-name
我想将其更改为:
http://www.city-name.domain.co.uk/index.php/city/details/city-name
或:
答案 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>