.htaccess for CakePHP and joomla in subfolder/subd

2019-09-05 05:06发布

I have working CakePHP app on web server, and now I want to have WIP joomla on subdomain. And because of my webhosting way to deal with subdomains I'm unable to write proper conditions in htaccess to have it working. By default my CakePHP app is in /www fodler on the server and its htacces look as follows

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

My webhosting provider way to deal with subdomains is to create folder inside subfolder of /www that is named as required subdomain and redirect to it.

So if I want to create subdomain joomla.mydomain.com I have to create folder /www/subdom/joomla and than add proper conditions and rules to htaccess

# subdomains(with or without www in the begenning)
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

But when this is added to to htaccess cakePHP works as before, but acessing joomla subdomain throws Internal Server Error. However if I comment out last rewrite rules

   #RewriteRule    ^$ app/webroot/    [L]
   #RewriteRule    (.*) app/webroot/$1 [L]

subdomain starts working properly.

1条回答
孤傲高冷的网名
2楼-- · 2019-09-05 05:15

I wrote a blog post on using other apps within CakePHP here

<IfModule mod_rewrite.c>
    RewriteEngine on

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

    # normal cake rules
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
 </IfModule>
查看更多
登录 后发表回答