[英]Apache mod_rewrite for a specific domain under same directory
I have wrote a website using PHP & Yii Framework, and there I have my .htaccess
file which has this mod_rewrite
statement to use clean URL's: 我已经使用PHP和Yii Framework编写了一个网站,并且我有.htaccess
文件,该文件具有此mod_rewrite
语句以使用干净的URL:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
For example I use this domain: www.example.com
& popstan.net
, and URL rewriting for these domains works like in a dream! 例如,我使用以下域名: www.example.com
& popstan.net
,这些域名的URL重写就像在梦中一样!
However, I'm now creating a blog, and with my Yii controllers I have this structure for accessing blog articles, blog categories and single blog article: 但是,我现在正在创建一个博客,并且使用Yii控制器,我可以使用以下结构来访问博客文章,博客类别和单个博客文章:
Now, I wish to use this blog, but under domain: http://blog.example.com/
, and to maintain those URL structures, and I wish not to copy my website on two separate directoryies (ie. blog directory). 现在,我希望使用该博客,但要使用以下域名: http://blog.example.com/
: http://blog.example.com/
,并维护这些URL结构,并且我不想在两个单独的目录(即Blog目录)上复制我的网站。
Is it possible to use mod_rewrite
to rewrite URL's for a domain, but to have the URL's be fetched from a parent directory? 是否可以使用mod_rewrite
重写域的URL,但可以从父目录中获取URL?
You should simply : 您应该简单地:
1) create a blog.example.com
virtual host that points to the same directory, 1)创建指向相同目录的blog.example.com
虚拟主机 ,
2) define corresponding url rules in Yii config, eg : 2)在Yii配置中定义相应的url规则,例如:
'http://blog.example.com/<action:\w+>/<param:\w+>'=>'/blog/<action>',
'http://blog.example.com/'=>'/blog/index',
You don't need to modify your .htaccess
. 您无需修改.htaccess
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.