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?
Related
My question is the same as: Zend Framework 2 without Vhost configuration but the solution didn't solve my problem.
I'm getting a customised 404 page.
my project is in a sub-directory, and I believe the .htaccess in the parent directory is stopping it from working.
note: I can't delete that one because there is another project running there
htdocs/.htaccess:
Options -Indexes
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^transcripts/$ https://spreadsheets.google.com/a/ci4tcm.com/ccc? key=0AodnCB9Mr1K1dFFmbGhOc3V4RjBvNzZxSE9EZ1dtSnc&hl=en#gid=0 [R,NC]
# ErrorDocument 404 /pages/404.html
# ErrorDocument 500 /pages/404.html
# ErrorDocument 403 /pages/404.html
# RewriteRule ^css(/)?$ / [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)$ /download/$1/$2/ [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)/$ /download.php?test=$2&fol=$1
RewriteRule ^download/([A-Za-z0-9.]*)$ /download/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)/([A-Za-z0-9\+.-\s]*)$ /download.php?folder=$1&file=$2 [L]
RewriteRule ^download/([A-Za-z0-9.]*)$ /posters/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)$ /images/wellbeing_posters/pdfs/$1 [L]
AddHandler server-parsed html
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.another-domain\.com\/$1" [R=301,L]
# A bunch of redirect 303's here
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
htdocs/booking/ < Zend application here > (solution to other question).
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} = ""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
so my question is, how do I bypass the parent directory .htaccess rule when the user wants to enter the physical sub directory with the Zend Application?
Your edited question added a whole load of stuff to the .htaccess in the parent folder which changes things somewhat. Assuming you're able to edit that htaccess, the easiest thing to do would be to move the ZF rules into it. Just change any lines that include public and add c-booking before it. So as an example, the last line would look like:
RewriteRule ^c-booking/public/.*$ /c-booking/public/index.php [NC,L]
Also be aware that this is a less secure way to host an app. If you have any non-PHP config files, cache files etc. (things that would normally be outside the web root), make sure they aren't viewable through a browser.
I have this path in my hosting server with domain http://www.example.com/ and it's running cakephp in the directory home. but now I want my another_project_name appear in browser with http://www.example.com/another_project_name/.
This is my structure :
/www
.htaccess
home/
.htaccess
webroot/
.htaccess
lib/
another_project_name/
This is my /www/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ home/webroot/ [L]
RewriteRule (.*) home/webroot/$1 [L]
</IfModule>
How to configure .htaccess file in /www/.htaccess to make my another_project_name work ?
Try this
<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>
.htaccess file should be like this
<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>
For multiple directories
RewriteCond %{REQUEST_URI} ^/?(another_project_name1 | another_project_name2 | another_project_name3 )/(.*)$
I have a lithium installation and all the .htaccess works fine.
I need to install OpenCart as a shopping cart in app/webroot/shop
I copied all the files and also changed the .htaccess file in the root folder of lithium installation as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule shop/(.*) /app/webroot/shop/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Still when I browse http://domain.com/shop it takes me to http://domain.com/app/webroot/shop/
With an error on page:
Exception
lithium\action\DispatchException (code 404)
Action `webroot` not found.
Please help me in solving this problem.
You may try this instead:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/app/webroot/shop/? [NC]
RewriteRule ^shop/(.*) /app/webroot/shop/$1 [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^$ /app/webroot/ [L,NC]
RewriteCond %{REQUEST_URI} !/app/webroot/? [NC]
RewriteRule ^(.*) /app/webroot/$1 [L,NC]
</IfModule>
The problem is that your last "catch all" rule is also redirecting all requests for the shop to lithium, which you don't want.
Try this
Options +FollowSymlinks -MultiViews
RewriteEngine On
# Rewrite all URLs that start with /shop to /app/webroot/shop
RewriteRule ^shop/.? /app/webroot/shop%{REQUEST_URI} [L]
# Rewrite all URLs that don't start with /app/webroot/shop to /app/webroot
RewriteCond %{REQUEST_URI} !^/app/webroot/shop
RewriteRule .? /app/webroot%{REQUEST_URI} [L]
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
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>