如何让其他子目录在root中使用cakephp?

时间:2014-01-24 09:40:51

标签: .htaccess cakephp

我在托管服务器中使用域http://www.example.com/,并在目录home中运行cakephp。但现在我希望我的another_project_name在浏览器中显示为http://www.example.com/another_project_name/

这是我的结构:

/www
    .htaccess
    home/
        .htaccess
        webroot/
            .htaccess
    lib/
    another_project_name/

这是我的/www/.htaccess

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ home/webroot/    [L]
   RewriteRule    (.*) home/webroot/$1 [L]
</IfModule>

如何在.htaccess中配置/www/.htaccess文件以使another_project_name正常工作?

2 个答案:

答案 0 :(得分:0)

试试这个

<IfModule mod_rewrite.c>
   RewriteEngine on

RewriteRule (another_project_name/.*) $1 [L] # adjust the regex to what you want.
RewriteRule (another_project_name.*) $1 [L] # adjust the regex to what you want.

RewriteRule    ^$ home/webroot/    [L]
   RewriteRule    (.*) home/webroot/$1 [L]
</IfModule>

答案 1 :(得分:0)

.htaccess文件应该是这样的

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/?(another_project_name)/(.*)$ 
    RewriteRule ^.*$ - [L]
</IfModule>

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

对于多个目录

RewriteCond %{REQUEST_URI} ^/?(another_project_name1 | another_project_name2 | another_project_name3 )/(.*)$