Codeigniter Cannot Remove index.php after move to virtual host - codeigniter

I created the virtual in wamp server. Everything is working but i can't able to remove the index.php. I don't know how to write the .htaccess.
Here is the details
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot E:/Projects/OnGoing/bonanza/dev.bonanza.com
ServerName dev.bonanza.com
<Directory "E:/Projects/OnGoing/bonanza/dev.bonanza.com">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and my htaccess
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Allow these directories and files to be displayed directly:
# - index.php (DO NOT FORGET THIS!)
# - robots.txt
# - favicon.ico
# - Any file inside of the media/ directory
RewriteRule ^(index\.php|robots\.txt|favicon\.ico|media|uploads|js|css|images|plugins|source|files|fonts|lib|plugins) - [PT,L]
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php?/$0 [PT,L,QSA]

Did you setup your host file correctly to read the path of your site? For me I used this all the time works fine in development server.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

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 Treating www and non www different

I have windows server and have domain of godaddy. I took SSL from godaddy and apply on my server. My domain gets secure by SSL but problem come when, i redirect from https://www.example.com and logged in it shows dashboard but when i change url to https://example.com it redirect me to login page.
Here is my VHOST file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:/mcpluat/xampp/htdocs/project/public"
ServerName www.example.com
ServerAlias example.com
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/ [R,L]
<Directory "C:/mcpluat/xampp/htdocs/project/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
.HTACCESS file
Options -MultiViews -Indexes
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]
Everything is working perfectly but why it is treating www.example.com and example.com a different domain
Thanks in advance

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).

Laravel 5.5 and .htaccess - images and css files are not loading

I have a brand new virtual server with Apache2. I'm trying to start my Laravel 5.5 project.
It's working fine in my Homestead enviroment, but on this server it isn't work.
I'm using this apache config:
<VirtualHost *:80>
ServerName www.myproject.com
ServerAlias myproject.com new.myproject.com
ServerAdmin webmaster#myadmin.com
DocumentRoot /var/www/www.myproject.com/current/public
CustomLog /var/www/www.myproject.com/log/access.log vhost_combined
ErrorLog /var/www/www.myproject.com/log/error.log
RewriteEngine On
LogLevel alert rewrite:trace3
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /var/www/www.myproject.com/current/public/index.php [L]
<Directory />
AllowOverride None
Order Deny,Allow
Deny from all
</Directory>
<Directory /var/www/www.myproject.com/current/public>
Options FollowSymLinks MultiViews
Require all granted
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now the main page is loaded well, but if I click on Login or Register menu, witch are a Laravel handled and Blade template based pages it's showed, but the CSS, JS and images are not loading. Files are sitting on their place in public/ folder, they are not null-sized, and still not loading.
If I click on login page, instead of these files (css, js, images) the login pages showed...
Has anybody any idea?
Replace .htaccess with following and create .htaccess file outside public folder.
RewriteEngine On
#----------------------------------------------
# | this code use for remove public directory |
#----------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.ico|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt|\.eot|\.svg|\.ttf|\.woff|\.woff2|\.otf|\.pdf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(login|uploads|assets|css|js|images|ca|favicons|fonts|)/(.*)$ public/$1/$2 [L,NC]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

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>

Resources