I need help with CodeIgniter -- trying to it to work in virtual host envirnoment in Ampps.
I have been following the following tutorial:
http://net.tutsplus.com/tutorials/php/basecamp-style-subdomains-with-codeigniter/
I am trying to have two installations of CodeIgniter running in two directories:
/students and
/teachers
www.test.com -> goes to /teachers directory
www.user1.test.com -> goes to /students directory
I have the above working on my local machine. The different URL's take me to the correct directory. CI works. Problem arises when I try to access controller using redirect.
if I try to redirect('error') I get:
user2.test.com/user2.test.com/error
Also get an "internal server error"
if I type in
user2.test.com/error
I get an "internal server error"
if I type in
user2.test.com/index.php/error
I get desired result
It works if I try to load view directly in
$this->load->view('error')
I think I need help with the urls and paths. Any guidance most gratefully received.
Nothing particularly enlightening in CI log files
In Apache logs I find:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Things I have changed:
htaccess in root - changed rewrite base. Also takes out index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /students/
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>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
application/config.php
$config['base_url'] = $_SERVER['HTTP_HOST'];
As per tutorial. Needs to be dynamic.
my Apache hppd-vhosts.conf file
NameVirtualHost 127.0.0.1:80
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/Program Files/Ampps/www/teachers"
ServerName test.com
ServerAlias test.com
<Directory "C:/Program Files/Ampps/www/teachers">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Program Files/Ampps/www/students"
ServerName test.com
ServerAlias *.test.com
<Directory "C:/Program Files/Ampps/www/students">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
index.php in root
kept as is. Things got worse when I tried to change these
$system_path = 'system';
$application_folder = 'application';
what about your host file? your host file should be 127.0.0.1 test.com and first try to disable the student sub domain and see if it dose work. Its look like your both ServerName test.com is same try to change the other one with student.com and see whats happen most probably both are conflicting
Related
I have a website build with Codeigniter HMVC. On my local machine using Wamp it runs like it should. I want to upload it to my webserver that has an SSL certificate.
No matter what i try, i cant get the website to run on my webserver. I have tried following this :
How to force ssl in codeigniter?
But none of the given solutions work in my situation.
my .htaccess file looks like this :
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
in config.php of codeigniter i have :
$config['base_url'] = 'https://www.example.com/';
my webserver is an ubuntu 16 machine with apache, using an letsencrypt certificate. mod rewrite is enabled, but besides that is a standard configuration.
I have tried redirecting with hooks as mentioned in the link above, but to no avail. I have also tried various .htaccess file configuration but also no result there.
Is there anyone who has this running on their server?
regards,
sander
Because you say,
my webserver is an ubuntu 16 machine
I assume you are not using a shared server from a hosting provider and so you have complete access to Apache's configuration files. If that is true then you should not use .htaccess files. Read THIS and THIS to learn why.
I also assume you have a set of Apache "sites-available" files that define <VirtualHost> configs. It is inside those <VirtualHost> blocks where you should be placing the code you currently have in .htaccess.
To redirect all http requests to https try this as the contents of the "default" site in a "sites-available" configuration file e.g. "000-default.conf"
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
RedirectMatch 301 (.*) https://www.example.com$1
</VirtualHost>
What this will do is take any http request and immediately redirect to the https: URL. If you are using some other port besides the typical :80, adjust accordingly.
As mentioned, you can do the rewriting in a VirtualHost. Here's an example for the https: config file (maybe named along the lines of "020-example-443.conf")
<VirtualHost *:443>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/whatever
ServerAdmin web-boss#example.com
<Directory /var/www/whatever>
DirectoryIndex index.php
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [PT]
</Directory>
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# Certificates delivered by certbot - your's maybe elsewhere
SSLCertificateFile /etc/letsencrypt/live/yoursite/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yoursite/privkey.pem
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
With these in place, you won't have to do anything special in CodeIgniter except, as you already do, use the following
$config['base_url'] = 'https://www.example.com/';
You must add after RewriteEngine on
<IfModule mod_ssl.c>
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
I've been having a problem setting a directory in my virtualhosts, and am wondering if you guys can help. This is for Laravel and I have already made sure that the location exists and SELinux is disabled.
My config is as follows:
http://i.gyazo.com/31cdec5f9d830ec43923b4ccf1588d4c.png
I can't paste it here because the symbols mess up the formatting.
You should change your document root to:
/var/www/QuickPush/public
See the following virtualhost configuration I always use under CentOS 6:
<VirtualHost *:80>
ServerName quickpush.jackryder.co.uk
DocumentRoot /var/www/QuickPush/public
<Directory /var/www/QuickPush/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
I know this is quite old problem, but i have no luck when trying to find the right solution. I have tried every possible configuration but still no luck. I'm working on PHP project using laravel. I got no problem at all when set up the laravel.labs as vhost INSIDE the htdocs. But when I move it into separated folder which is C:\vhosts i got this 403 error. The purpose of vhosts folder is to hold multiple vhost. The following are my configuration:
System:
windows 7 64-bit
XAMPP v 1.7.7
Apache/2.2.21
PHP: 5.3.8
httpd.conf :
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/vhosts/laravel_labs/public
ServerName laravel.labs
</VirtualHost>
c:\windows\system32\driver\etc\host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 laravel.labs
.htaccess (inside the C:\vhosts\laravel_labs\public)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Can anyone help to find something that i missed? any advice guys? thanks
Every time you add a new Alias or DocumentRoot, you need a <directory> section just like the one for your default DocumentRoot. Depending on your release, this either has something like
Order deny,allow
or
require all granted
Finally i found The answer for this problem. I have to add some lines in httpd.conf
Something like this:
Alias /laravel_labs/public "C:/vhosts/laravel_labs/public/"
<Directory "C:/vhosts/laravel_labs/public/">
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
See the detail explanation here :
http://www.youtube.com/watch?v=Z250saioXIs
I have the following vhosts file:
directoryindex .index.php index.html index.php
options -indexes -multiviews +followsymlinks
<directory /Volumes/dev1/http>
allowoverride all
</directory>
<virtualhost *:80>
documentroot "/Volumes/dev1/http"
rewriteengine on
rewriterule ^.*$ /msg.php [l]
</virtualhost>
There are other virtual hosts, but the one from above is the "catch-all". The problem is that the rewriterule is totally ignored.
Going to site.com gives a 403 error and site.com/test just returns a 404 Not Found page instead of serving the msg.php file.
The server is a OS X 10.8 Server running Apache 2.2.24
it seems that you are in the wrong dir.
For what reason ever Apple left the .conf files for the virtual host under this directory.
/Library/Server/Web/Config/apache2/sites
I wanted to move my .htaccess file - redirects into my vhost conf file...
This was working - but the htaccess redirects were not...
<VirtualHost *:80>
ServerName dev.x.com
ServerAlias dev.x.com
DocumentRoot "C:/wwwroot/x"
Alias /modules/ "C:/wwwroot/x/_my_modules/"
ErrorLog "C:/wwwroot/x/_my_logs/error.log"
CustomLog "C:/wwwroot/x/_my_logs/access.log" combined
<Directory "C:/wwwroot/x/_my_logs/" >
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
</VirtualHost>
Then i did this -
<VirtualHost *:80>
ServerName dev.x.com
ServerAlias dev.x.com
DocumentRoot "C:/wwwroot/x"
Alias /modules/ "C:/wwwroot/x/_my_modules/"
ErrorLog "C:/wwwroot/x/_my_logs/error.log"
CustomLog "C:/wwwroot/x/_my_logs/access.log" combined
<Directory "C:/wwwroot/x/_my_logs/" >
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
RewriteEngine on
# if requested URI is not a file and not a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# externally redirect to /newLocation/{URI}
# RewriteRule (.*) index.php?_req=$1 [L]
# could use a redirect to a new directory ---
RewriteRule ^ /_mf_modules%{REQUEST_URI} [L,R=301]
</VirtualHost>
My objective was this:
I wanted any "directory" request - that didn't exist - to be rerouted to a directory of that name in the _my_modules dir.
IF a file did not exist I wanted to redirect to the to a directory of that name in the _my_modules dir.
So if www.x.com/xxx was the url... and 'xxx' dir didn't exist, I'd redirect to www.x.com/_my_modules/xxx
and like wise if www.x.com/xxx.php was requested - but xxx.php DIDN'T exist, they wou be redirected to www.x.com/_my_modules/xxx
however (even though there is an index.php in each dir) these always results in th eURL redirecting to this...
The requested URL /modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/modules/_my_modules/ was not found on this server.
So I got fed up and changed the vhost file back to what I had to begin with, restarted Apache, and it's still redirecting, I can't get rid of the behavior.
You can move the RewriteRules from a .htaccess to the VirtualHost environment by putting them in a <Directory> environment in your vhost configuration.
In your case, try to cut and paste your rewrite rules in <Directory "C:/wwwroot/x/_my_logs/" >
If you really want to put them in the VirtualHost environment, you have to modify the paths in them: RewriteRules in .htaccess or are relative to the directory, RewriteRules in the VirtualHost are absolute to the root of the filesystem or the DocumentRoot.
rewritecond example:
RewriteCond %{REQUEST_FILENAME} !-f
should be in vhost:
RewriteCond /your/documentroot/%{REQUEST_FILENAME} !-f
rewriterule example:
RewriteRule (.*) /your/documentroot/index.php?_req=$1 [L]
should be in vhost:
RewriteRule (.*) index.php?_req=$1 [L]