Manage virtual host in CodeIgniter - 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/

Related

Rewrite rules for several laravel apps in the same Virtual Host

I have an Apache2 virtual host where I'll be hosting several Laravel applications.
The VH document root is /home/user/applications/portal.
The laravel applications are in:
/home/user/applications/portal/larapps/larapp1
/home/user/applications/portal/larapps/larapp2
...
I want the URLs to be like:
http://portal.com/larapp1/...
http://portal.com/larapp2/...
So this is my config:
<VirtualHost *:80>
ServerName portal.com
DocumentRoot /home/user/applications/portal
Alias /larapp1 /home/user/applications/portal/larapps/larapp1/public
<Directory /home/user/applications/portal/larapps/larapp1/public>
RewriteEngine On
RewriteBase /larapps/larapp1/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
</Directory>
</VirtualHost>
If the request is http://portal.com/larapp1 then the route that matches is as I expect: Route::get('/',...).
But, inexpectedly, if I add any URI in the request, it doesn't do what I want. For example, if the request is http://portal.com/larapp1/foo, it doesn't match Route::get('/foo',...) but Route::get('/larapp1/foo',...).
What should I do so that routes are matched without the prefix /larapp1?
I found it! My bad, I did a mistake in the configuration: I used a filesystem path in RewriteBase, when I should have indicated a base URI. This is the right config:
<VirtualHost *:80>
ServerName portal.com
DocumentRoot /home/user/applications/portal
Alias /larapp1 /home/user/applications/portal/larapps/larapp1/public
<Directory /home/user/applications/portal/larapps/larapp1/public>
RewriteEngine On
RewriteBase /larapp1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
</Directory>
</VirtualHost>

Laravel - set /public as root on LAMP stack

I'm trying to deploy a Laravel App on a LAMP stack although I am having trouble setting the document root as /public. I've looked at several answers on here already for similar problems but am yet to find my problem or a solution. I ideally I want to do it through the Apache web server and not modify any Laravel files.
I copied the default .conf file a change it to the following using sudo nano /etc/apache2/sites-available/subdomain.website.com.conf
<VirtualHost *:80>
ServerAdmin email#gmail.com
ServerName subdomain.website.com
ServerAlias www.subdomain.website.com
DocumentRoot /var/www/subdomain.website.com/public_html/public
<Directory /var/www/subdomain.website.com/public_html/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.subdomain.website.com [OR]
RewriteCond %{SERVER_NAME} =subdomain.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
After the I ran the following commands in this order.
sudo a2ensite subdomain.website.com.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
sudo service apache2 restart
I cleared cookies, did a hard refresh and it hasn't worked. I still have to go to https://subdomain.website.com/public to view the website. Is there anything I have missed or anything I can do find out what the problem may be?
The .htaccess file in the /public folder contains the following
<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>
This virtualhost is for http:// (Port 80). You have a rewrite rule that redirects to https:// as soon as it hits this virtualhost.
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.subdomain.website.com [OR]
RewriteCond %{SERVER_NAME} =subdomain.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Therefore, you need to apply your changes to the other virtualhost that is serving this domain from https:// (Port 443).

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>

CakePHP only works on Mac local when using VirtualHost

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]

Rewrite everything to be after index.php/

I'm setting up a php mvc framework and I want to redirect anything after the domain to index.php/$1 but it's not working. I have rewrite_module enabled and AllowOverride All, is there something else I'm missing?
Basically I want the url to go from this http://www.example.com/foo/bar to http://www.example.com/index.php/foo/bar so I can grab it from $_SERVER['PATH_INFO']
Here's what I have...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot c:/wamp/www
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/websites/snugglemvc"
ServerName www.snugglemvc.com
<Directory "c:/websites/snugglemvc">
Order Deny,Allow
Allow from all
AllowOverride all
</Directory>
</VirtualHost>
I believe you need the leading slash on /index.php as your regex matches beginning of line.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
it was an issue with my httpd.conf file. i didn't have AllowOverride all on the localhost. once I changed that everything worked.

Resources