.htaccess rules to have CakePHP in root and WordPress in subfolder - .htaccess

How can I combine the .htaccess rules for CakePHP
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
with the following
RewriteEngine On
RewriteCond %{HTTP_HOST} folder.yoursite.com
RewriteRule ^(.*)$ /folder [L]
in other words redirect anything to app/webroot/ except /blog (which is an existing folder with a WordPress installation) and redirect blog.domain.com to the blog subfolder.

It should work automatically (at least with CakePHP 1.3), it's working for me...
My .htaccess looks like this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
You should also have a proper .htaccess in your wordpress (or any other application) folder that's not a part of the CakePHP application.

Related

htaccess file to hide subfolder

I'm struggling with the .htaccess file. I've wordpress installed in a subdirectory 'wordpress'. In the root folder if have the htaccess with the following content:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule !^wordpress/ /wordpress%{REQUEST_URI} [L,R=301]
</IfModule>
Redirection is working, but how can I hide the subfolder 'wordpress'?
THX in advance
EDIT: Tried following content now but still not working:
root htaccess:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
</IfModule>
wordpress htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
EDIT2: my whole root htaccess looks like this now:
Allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
If i type in www.example.com I am redirected to example/wordpress/home, example/wordpress/contact and so on...
I would like to hide the wordpress directory like example/home, example/contact and so on
Redirection is working, but how can I hide the subfolder 'wordpress'?
You shouldn't be "redirecting". You should be internally rewriting the request instead. Remove the R flag.
For example:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
The slash prefix on the susbtitution string is also not required.
This assumes you have the standard WP .htaccess file in the /wordpress subdirectory.
UPDATE: Also confirm you have removed the /wordpress subdirectory from the "Website Address" and "Site Address" in WordPress General settings.

htaccess conditional rewrites

Im using an MVC framework for my PHP application which works great. I have the below code in a .htaccess file in the root folder of my application. This redirects everything to the public folder which is causing issues for me. I want to apply the below to everyfolder apart from one. How would I go about doing this? ie. need to access the /dompdf/ directory and all subdirectories normally wihtout the below rule which redirects.
#<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
# </IfModule>
I think if I understand what you want, this should help -
#<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^dompdf [L,NC]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
# </IfModule>
Replace your existing code with this one:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule (?!^(dompdf|public)/)^.*$ public%{REQUEST_URI} [L,NC]
Negative lookahead will prevent application of these rules for paths dompdf and public.

Making CakePHP 2.0 work on a subdirectory

I have my site www.mysite.com in /var/www/
and I added my cakephp app in /var/www/developer
when I go to www.mysite.com/developer I get the login page fine and after I login the app takes me to the home page OK. But whenever I click on other link I get
"Page not found"
I have 3 htaccess
/var/www/developer
/var/www/developer/app
/var/www/developer/app/webroot
What should I put on those to make my urls work?
Thanks
Your .htaccess files should probably look like this:
/var/www/developer
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/var/www/developer/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/var/www/developer/app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
You also should have right paths defined in /var/www/developer/app/webroot/index.php
instead of
if (!defined('ROOT')) {
define('ROOT', dirname(dirname(dirname(__FILE__))));
}
try something specify the right way (eq. DS . 'www' . 'develop')
usually it is enough to redefine just CAKE_CORE_INCLUDE_PATH but sometimes youe needed define all three ROOT WEBROOT_DIR nad CAKE_CORE_INCLUDE_PATH

CakePHP, .htaccess and subdomain not working together

I have the following directory tree in public_html folder:
/app
/test
/cake
...
/app if the Application folder for my site and /test is a subdomain.
The problem is that I've changed the .htaccess, my site is working but the subdomain is returning a 500 error.
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Thanks.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Add the RewriteCond below to prevent an infinite internal redirect, which could result in a 500 error
#skip processing existing files e.g css. png etc
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^$ app/webroot/ [L]
#if not already /app/webroot to prevent infinite internal redirect
RewriteCond %{REQUEST_URI} !^/app/webroot/ [NC]
RewriteRule (.*) app/webroot/$1 [L]
500 error usually means something is wrong with the code, like a missing ; in your model, view or controller. Try double-checking that?

CakePHP .htaccess mod_rewrite configuration to exclude a particular folder/url

I have a CakePHP installation in a sub folder in my server, I want to install another application inside that subfolder:
root/public_html/subfolder/cake/
root/public_html/subfolder/app/
etc. now I need a custom application installed there:
root/public_html/subfolder/my_custom_application/
I have something like this in my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
How can I configure it to exclude the "my_custom_application" folder from that rules?
I tried this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule ((?!my_custom_application).*) app/webroot/$1 [L]
</IfModule>
But I get this:
Error: The requested address '/y_custom_application' was not found on this server.
Thanks in advance.
Mauricio.
How to Exclude a Directory from CakePHP Routing:
I ran into the same problem as you. I struggled, but finally found something that worked.
(I'm replying because the answer above didn't work for me, but this did).
My directory structure:
root/public_html/app/
root/public_html/lib/
root/public_html/plugins/
root/public_html/vendors/
root/public_html/directory_to_exclude/
What I added to CakePHP's default routing:
RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)
Effectively, I needed to allow people to access the subfolder separately (since that has a separate application). Also, in my case, I'm serving a CakePHP application by default from the root directory.
So here's what my CakePHP 2.x htaccess looks like:
Updated .Htaccess (this works for me)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
In your case, I understand you need this to work in a subfolder; here's my adjusted htaccess I didn't have a chance to test this, but I believe this (or something close) will work:
The Final Product (for a subfolder)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subfolder/directory_to_exclude/(.*)
RewriteRule ^$ subfolder/app/webroot/ [L]
RewriteRule (.*) subfolder/app/webroot/$1 [L]
</IfModule>
Put this before the RewriteRule lines:
RewriteCond %{REQUEST_URI} !^/my_custom_application
You have to replace dir_to_exclude by your dir name.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude)(?:$|/)
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude)(?:$|/)
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
If you want to have more than one excluded directory you have to add them separated by |additional_dir_to_exclude
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude|additional_dir_to_exclude)(?:$|/)
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/(?:dir_to_exclude|additional_dir_to_exclude)(?:$|/)
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Resources