Codeigniter url rewrite like subdomain url with .h

2019-09-09 00:10发布

1条回答
劫难
2楼-- · 2019-09-09 01:00

Put the .htaccess file into the http ://www.domain.co.uk/ document root

To 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]

To 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] 

If the server is the same, set above RewriteRule this line to prevent redirection loop

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

File content example

<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>

To exclude 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>
查看更多
登录 后发表回答