CakePHP only works on Mac local when using VirtualHost - macos

I have a CakePHP 2.x app here: /Users/cameron/Sites/ExampleApplication
And inside it has the standard structure:
/app
/webroot
etc.
However when I go to:
localhost/~cameron/ExampleApplication
I get the error: The requested URL /Users/cameron/Sites/ExampleApplication/app/webroot/ was not found on this server.
However if I setup a VirtualHost like:
<Directory "/Users/cameron/Sites">
Header set Access-Control-Allow-Origin "*"
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "/Users/cameron/Sites/ExampleApplication"
ServerName example.com
UseCanonicalName Off
</VirtualHost>
It works fine!
Any ideas why it works for the VirtualHost but NOT when accessing it via the usual localhost?
Here is what is inside the three .htaccess files:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

If you use Mamp, you have to configure the htaccess file
and modify htaccess in folder root / app/webroot and app/config
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase / "production" or /nameFolder/ "dev"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

Related

HTTPS: Laravel using .htaccess (public/)

I'm trying to include https in my Laravel Project without using godaddy only using htaccess and not that big deal since I'm using proxypass from my SSL certified website that will pass to my laravel project.
I just need to make my laravel project to https.
So I tried to add this code to my .htaccess located at public/
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://myproject.com/$1 [R=301,L]
Here's my public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
UPDATED
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
My httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/e-wallet-frontend/public"
ServerName localhost
<Directory "/opt/lampp/htdocs/e-wallet-frontend/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog "logs/frontendewallet.com-error_log"
CustomLog "logs/frontendewallet.com-access_log" common
</VirtualHost>
the HTTPS appears but the browser says Object not Found is there something wrong with my htaccess?
RewriteRule ^(.*)$ https://www.myproject.com/$1 [R=301,L]
This is the code I have on my multiple Laravel projects.

Htaccess - Redirecting to core domain instead of same file

My domain requests are redirecting to the root of the domain instead of the given file type when attempting to redirect non www to www.
For example; I want website ---.com/dogs to go to www.---.com/dogs but instead it goes to www.---.com.
I'm using Laravel. What could be wrong?
My htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
#rewrite
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Virtual Host:
<VirtualHost 1.1.1.1:443>
SSLEngine on
SSLCertificateFile /root/sslcert/--.pem
SSLCertificateKeyFile /root/sslcert/--.key
ServerName www.--.com
#ServerAlias --.com
DocumentRoot "/var/www/website-live/public"
<Directory /var/www/website-live/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I've tried removing the conditions i added for the redirect and no redirect occurs, so only with the two lines under #rewrite do these issues occur

Manage virtual host in CodeIgniter

I've confused using ubuntu for setting up virtual host for CI in apache2.
I have website for running in locally using virtual host, but when I open my navigation link like.
mysite.com/about_us
It can't be open, and said : 404 Not Found
This is my virtual host code
<VirtualHost *:80>
ServerAdmin webmaster#blade.co.loc
ServerName blade.co.loc
ServerAlias www.blade.co.loc
DocumentRoot /var/www/html/new/
<Directory /var/www/html/new/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And this is my .htaccess code
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /new/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Follow this steps. It will lead you in correct path. It has describe every details. And also check you have correctly given the link in routes.php. This is for creating virtual host in ubuntu
https://support.rackspace.com/how-to/set-up-apache-virtual-hosts-on-ubuntu/

mod_rewrite for Typical CMS-style Redirect

Is there a specific RewriteRule that would work for Magento and convert
http://<domainname>/index.php/<filename>
into
http://<domainname>/<filename>
According to phpinfo(), Loaded Modules lists mod_rewrite , so it appears to be enabled.
Here is the relevant section from .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
Any suggestions?
So it turns out that it wasn't a missing mod_rewrite rule. I fixed it by inserting the Directory section below into /etc/apache2/sites-available/dev.magecom.local.conf (The Directory section didn't exist at all in the previous version).
<VirtualHost *:80>
ServerName dev.magecom.local
ServerAlias www.dev.magecom.local
DocumentRoot /var/www/sites/dev.magecom.local/public_html/
<Directory /var/www/sites/dev.magecom.local/public_html/>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Symfony 1.4: Second app on custom domain?

PHP start scripts:
Primary app:
~ec2-user/project/web/index.php
Secondary app:
~ec2-user/project/web/api1.php
Apache configuration:
Excerpt from /etc/httpd/conf/httpd.conf:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/ec2-user/project/web
DirectoryIndex index.html index.php
<Directory /home/ec2-user/project/web>
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName 1.api.example.com # 1: version number
DocumentRoot /home/ec2-user/project/web
<Directory /home/ec2-user/project/web>
AllowOverride None
</Directory>
RewriteEngine On
RewriteRule ^(.*)$ /api1_dev.php [QSA,L]
</VirtualHost>
~ec2-user/project/web/.htaccess (should only apply to primary app):
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
What loads as expected:
http://example.com: home page
http://example.com/api1.php/foo/bar: some JSON data
What doesn't load:
http://1.app.example.com/foo/bar:
404 | Not Found | sfError404Exception
Empty module and/or action after parsing the URL "/" (/).
[…]
What am I missing?
In ~ec2-user/project/web/.htaccess,
Uncomment RewriteBase /, it becomes this:
Options +FollowSymLinks +ExecCGI
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
I got it to work by changing:
RewriteRule ^(.*)$ /api1_dev.php [QSA,L]
into:
RewriteRule ^(.*)$ /api1_dev.php/$1 [QSA,L]
Makes sense. I only wonder why in the .htaccess for example.com, the $1
is not necessary:
RewriteRule ^(.*)$ index.php [QSA,L]

Resources