codeigniter URL重写像子域网址用的.htaccess [英] Codeigniter url rewrite like subdomain url with .htaccess

查看:121
本文介绍了codeigniter URL重写像子域网址用的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的网址是: HTTP://www.domain .co.uk / index.php文件/城市/信息/城市名称

我想将其更改为:

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

HTTP://www.city-name.domain。 co.uk/city/details/city-name

推荐答案

把.htaccess文件到HTTP://www.domain.co.uk/文档根目录

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

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

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]

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

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] 

如果服务器是一样的,上面的重写规则设置这条线prevent重定向循环

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>

要排除domain.co.uk(whitout WWW)

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>

这篇关于codeigniter URL重写像子域网址用的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆