Rewrite rules for several laravel apps in the same Virtual Host - laravel

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>

Related

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

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>

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.

how to rewrite this simple url?

how can i rewrite
www.mysite.com/someURLhere
into
www.mysite.com/ping.php?url=someURLhere
without mistaking local files, and directories as domains.
so i dont want
www.mysite.com/index.php
www.mysite.com/admin/
to rewrite to
www.mysite.com/ping.php?url=index.php
www.mysite.com/ping.php?url=admin/
<VirtualHost *:80>
ServerName yoursite.com
DocumentRoot /www/yoursite
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ping.php?url=$1 [L,QSA]
</VirtualHost>
If this is a .htaccess file you dont need %{DOCUMENT_ROOT} in both instances.

Resources