I have a Virtual Host in a WAMP server. To acces that VH, you need to authenticate to a LDAP server, so I configured it like this:
<VirtualHost *:80>
ServerName myserver
DocumentRoot /apps/portal/public
<Directory "/apps">
Options FollowSymLinks
AllowOverride None
AuthType Basic
AuthBasicProvider ldap
AuthName "My Autenticacion"
AuthLDAPURL "ldaps://myldapserver:636/DC=DOM1,DC=COM?sAMAccountName,memberOf?sub?(objectClass=*)"
AuthLDAPBindDN myuser
AuthLDAPBindPassword mysecret
LDAPReferrals Off
Require valid-user
</Directory>
# My Laravel 7 app:
Alias /myapp /apps/myapp/public
<Directory "/apps/myapp/public">
# Laravel rewrites:
RewriteEngine On
RewriteBase /myapp/
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
</VirtualHost>
So, all applications are under the /apps local directory. You can access the host via http://myserver. You can access the Laravel 7 application via http://myserver/myapp.
In that application I read the contents of the PHP variable $_SERVER['AUTHENTICATE_MEMBEROF']. When I visit http://myserver/myapp everything goes fine. But let's say I define one route like this:
Route::get('about', function() {
return view('about');
})->name('about');
Really simple. But as soon as I go to http://myserver/myapp/about, I get this error:
Undefined index: AUTHENTICATE_MEMBEROF
Furthermore, I've realized that none of the AUTHENTICATE_* server variables are served in this page. However, if I want to access http://myserver/myapp/about, the server prompts for credentials. So it's authenticating the user, but not serving the AUTHENTICATE_* variables.
What am I missing?
EDIT: Well, finally, I've found out that in all these routes, all AUTHENTICATE_* variables are available through a different name, which is REDIRECT_AUTHENTICATE_*, which doesn't seem to be documented anywhere. I assume this has to do with the rewrites, but anyone could explain why this new names, and whether it is possible or not to avoid these renamings?
Related
Solution
The solution was found thanks to #Gert B.
Simply add to your Laravel application any virtual host (I added for mine)
laravel1.test
How to add Virtual host:
Go to C:\Windows\System32\drivers\etc\hosts
add line:
127.0.0.1 laravel1.test (or your virtual host name)
And add this to your vhosts(in case of using xampp) in C:\xampp\apache\conf\extra httpd-vhosts
<VirtualHost *:80>
ServerName www.laravel1.test
ServerAlias laravel1.test
DocumentRoot "C:\xampp\htdocs\Laravel1\public"
<Directory "C:\xampp\htdocs\Laravel1\public">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
# Apache 2.4
Require all granted
## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I can't pass the problem with routing in Laravel 8.5 framework. I know there have been many requests about this problem so far but any of given solutions didnt help in my case. I will show Frontend code, since backend is the same thing and also doesnt work. Right now, the only thing that works is index.php.
I know thanks to newest Laravel all bugs are hidden under simple error 404.
Bug image
I already tried:
Changing in apache/conf/httpd solution AllowOverride All
Clearing whole cache and routes cache
Any possible misspells in code
Still, without any working anwser.
My FrontendController at app/Http/Controllers
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FrontendController extends Controller
{
public function index()
{
return view('frontend.index');
}
public function object()
{
return view('frontend.object');
}
public function article()
{
return view('frontend.article');
}
public function person()
{
return view('frontend.person');
}
public function room()
{
return view('frontend.room');
}
public function roomSearch()
{
return view('frontend.roomsearch');
}
}
My web.php at app/routes
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FrontendController;
##Frontend routes
Route::get('/','FrontendController#index')->name('index');
Route::get('/object','FrontendController#object')->name('object');
Route::get('/article','FrontendController#article')->name('article');
Route::get('/person','FrontendController#person')->name('person');
Route::get('/room','FrontendController#room')->name('room');
Route::get('/roomSearch','FrontendController#roomsearch')->name('roomSearch');
##Backend routes
Route::group(['prefix'=>'admin'],function(){
Route::get('/','BackendController#index')->name('adminHome');
Route::get('/cities','BackendController#cities')->name('cities');
Route::get('/myObjects','BackendController#myobjects')->name('myObjects');
Route::get('/profile','BackendController#profile')->name('profile');
Route::get('/saveObject','BackendController#saveobject')->name('saveObject');
Route::get('/saveRoom','BackendController#saveroom')->name('saveRoom');
});
.htacces file in app/public
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymlinks
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>
My routes
image
Solution
The solution was found thanks to #Gert B.
Simply add to your Laravel application any virtual host (I added for mine) laravel1.test
How to add Virtual host: Go to C:\Windows\System32\drivers\etc\hosts
add line:
127.0.0.1 laravel1.test (or your virtual host name)
And add this to your vhosts(in case of using xampp) in C:\xampp\apache\conf\extra httpd-vhosts
<VirtualHost *:80>
ServerName www.laravel1.test
ServerAlias laravel1.test
DocumentRoot "C:\xampp\htdocs\Laravel1\public"
<Directory "C:\xampp\htdocs\Laravel1\public">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
# Apache 2.4
Require all granted
## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I have an internal domain like
live.domain.com
which I defined in sites-available like so
ServerName live.domain.com
ServerAdmin webmaster#localhost
DocumentRoot /data/www/html/mydomainnamenodots
<Directory /data/www/html/mydomainnamenodots>
Require all granted
</Directory>
and the accordingly same for SSL conf.
I do have a folder /api which is in there like
/data/www/html/mydomainnamenodots/api
What I want is to catch all calls to
live.domain.com/api/*
and redirect them to something like
live.domain.com/api/index.php?url=*
So a real example would be
live.domain.com/api/statistics/getFTE/123/456
and I'd like that to be
live.domain.com/api/index.php?url=/statistics/getFTE/123/456
That would result in a $_REQUEST in index.php like so
array(1) {["url"]=>string(33) "/statistics/getFTE/123/456"}
mod_rewrite is enabled and loaded. Simple tests with file to file redirects work.
My rewrite rule which does not work as it does not redirect is
<Directory "/data/www/html/mydomainnamenodots/api">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*?mydomainnamenodots\/api(.*)$ /mydomainnamenodots/api/index.php?url=$1 [QSA,L]
</Directory>
Any ideas why that does not work?
Am I missing the RewriteBase or something?
Thanks in advance
Alex
As the subdomain already points to a subfolder, it has to be the the according subfolder below that one in the directory definition. In addition I changed the regexp as well.
Here is what worked for me:
<Directory />
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*\/api(\/.*)$ /api/index.php?url=\/$1 [QSA,L]
</Directory>
Version Information: Apache v2.4.18 on Ubuntu, PHP version 7.1,Symfony v3.2
I've been trying to get this working for a couple of days now and keep hitting problems, I have an existing PHP application using a custom built framework with the following Apache VirtualHost configuration:
<VirtualHost *:80>
ServerName dvlp.mydomain.com
DocumentRoot /var/www/my-site/com
RewriteEngine On
# Do nothing for the Home page ('^/$'), specific directories, static files.
RewriteRule ^/(?:$|shared|asset)|\.(?:php|ico|txt|xml) - [L]
# Search engine friendly request URIs (most, but not all, without a query string).
RewriteRule ^/([a-z0-9-]+/?)$ /index.php?param1=$1 [L,QSA]
RewriteRule ^/([a-z0-9-]+)/([a-z0-9-\.]+/?)$ /index.php?param1=$1¶m2=$2 [L,QSA]
RewriteRule ^/([a-z0-9-]+)/([a-z0-9-]+)/(.+)$ /index.php?param1=$1¶m2=$2¶m3=$3 [QSA]
<Directory />
Options FollowSymLinks
AllowOverride None
ErrorDocument 404 /404.php
</Directory>
</VirtualHost>
What I am trying to do is install a Symfony application to work within a sub-directory. I've created my Symfony application in /var/www/symfony-app and created a symbolic link /var/www/my-site/com/my-symfony which points to /var/www/symfony-app/web.
I then tried the following on line 6 of my VirtualHost file:
RewriteRule ^/(?:$|my-symfony|shared|asset)|\.(?:php|ico|txt|xml) - [L]
Visiting dvlp.mydomain.com/my-symfony in the browser takes me to the directory listings for the /var/www/symfony-app/web folder. I tried adding an index.php file to /var/www/symfony-app/web which simply includes app_dev.php and it loaded the home page, but I I tried visiting dvlp.mydomain.com/my-symfony/edit-personal-details I get the 404 error page from my existing application.
I realised now that I need separate rewrite rules for this sub-directory, for Symfony this is usually written as the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
So I undid the change I made to line 6 of the VirtualHost file and added a new line as follows:
RewriteRule ^/my-symfony(.*)$ /my-symfony/index.php [L,QSA]
This results in a 404 error:
No route found for "GET /my-symfony/" (from "http://dvlp.mydomain.com/")
And if I try visiting dvlp.mydomain.com/my-symfony/edit-personal-details I get the same 404 error:
No route found for "GET /my-symfony/edit-personal-details" (from "http://dvlp.mydomain.com/")
The last thing I have tried is adding a prefix to my Symfony routing.yml:
my_symfony:
resource: "#MySymfonyBundle/Controller/"
type: annotation
prefix: /my-symfony
This then loads the pages correctly but with no images or stylesheets because they are trying to load from the DocumentRoot (e.g dvlp.mydomain.com/css instead of dvlp.mydomain.com/my-symfony/css).
I would appreciate any input as to where I am going wrong. Thanks.
I finally managed to get this working as intended by adding a "Location" tag containing specific RewriteRules and a RewriteBase for the Symbolic link. For information, final VirtualHost config below:
<VirtualHost *:80>
ServerName dvlp.my-domain.com
DocumentRoot /var/www/my-site/com
RewriteEngine On
<Location /my-symfony>
RewriteBase /my-symfony
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
</Location>
# Do nothing for the Home page ('^/$'), specific directories, static files.
RewriteRule ^/(?:$|my-symfony|shared|asset)|\.(?:php|ico|txt|xml) - [L]
# Search engine friendly request URIs (most, but not all, without a query string).
RewriteRule ^/([a-z0-9-]+/?)$ /index.php?param1=$1 [L,QSA]
RewriteRule ^/([a-z0-9-]+)/([a-z0-9-\.]+/?)$ /index.php?param1=$1¶m2=$2 [L,QSA]
RewriteRule ^/([a-z0-9-]+)/([a-z0-9-]+)/(.+)$ /index.php?param1=$1¶m2=$2¶m3=$3 [QSA]
<Directory />
Options FollowSymLinks
AllowOverride None
ErrorDocument 404 /404.php
</Directory>
</VirtualHost>
I installed PHP and Apache server in my computer.
So inside of "htdocs" I created 2 files(index.php, Contact.php) and a directory(MyClass), after that inside of "MyClass" I created a file(class.php)..
In web browser when I am using the url "http://localhost/MyClass/class.php", the result is : "class.php" sending data to the web browser.
In the same situation is there any way in PHP/Apache to take control of it from the "index.php" ??
Or
I want to be known about all the requests inside of "index.php" which came from web browser, is it possible ????
But I don't want to use any GET variable like "http://localhost/index.php?class=page2"..
Apology for my bad English.
Thanks..
You should use include, in your case you would use
include 'MyClass/class.php';
More information about include can be found right here
I'm not sure I understand correctly but a way to not use ?class=page2
is to create a .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This will rewrite all requests to non existing files or folders to your index.php
the use $_SERVER['REQUEST_URI'] to make your navigation.
for example you could use http://localhost/class/page/2
$_SERVER['REQUEST_URI'] would then be class/page/2
If your website is in a subfolder of htdocs be sure to edit
RewriteBase /dir/here/
[...]
RewriteRule . /dir/here/index.php [L]
to match it
My problem solved.
Which changes I did they are below :
In "C:\Apache24\conf" need to change file "httpd.conf"
Just active :
1)
LoadModule rewrite_module modules/mod_rewrite.so
2)
<Directory />
#AllowOverride none
AllowOverride All
Require all denied
</Directory>
3) I am using "Virtual Host", so in "C:\Apache24\conf\extra" need to change file "httpd-vhosts.conf"
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#test.com
DocumentRoot "E:/TEST"
<Directory "E:/TEST">
Allow From All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
</Directory>
ServerName test.com
ServerAlias www.test.com
ErrorLog "logs/test.com-error.log"
CustomLog "logs/test.com-access.log" common
</VirtualHost>
If you are not using "Virtual Host", then I think you need to add some lines to the "Directory" inside of "httpd.conf" !!
<Directory>
Allow From All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
</Directory>
Use the PHP include function. You can include your MyClass/class.php in you index file. You can then add an htaccess file to restrict files in the MyClass directory from being viewed directly.
I have a zend site where DocRoot is set to public/ and URL as
(http://dothat.com/controllerA/action9/) - which is working properly.
I also need to run a copy of that site on the same server as
(http://dothat.com/now/controllerA/action9/) running on same folder.
(The urls given are examples)
Please suggest on how can this be done without spoiling zend setup itself.
I would personally just do a simple Zend route in your Bootstrap.
Example:
protected function _initRoutes()
{
$this->bootstrap('frontController');
$frontController = Zend_Controller_Front::getInstance();
$nowRoute = new Zend_Controller_Router_Route("now/:controller/:action");
$frontController->getRouter()->addRoute("now", $nowRoute);
}
Routes in Zend are very powerful and fun to setup. I actually have mine in an outside .ini file to make it easier to setup, even environment aware.
it's working for me
/etc/httpd/conf.d/zendproject.conf
Alias /zendproject/ /var/www/vhosts/zendproject/public/
<Directory "/var/www/vhosts/zendproject/public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from All
</Directory>
public/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /zendproject/index.php [NC,L]
How about that idea:
An alias in Apache (if it's the http server you're using)
Alias /now /path/to/zend/public
<Directory /path/to/zend/public>
SetEnv APPLICATION_ENV development
...
</Directory>
And you have to care for the .htacces too
...
RewriteRule ^.*$ /now/index.php [NC,L]
E.g. with another environmental variable for the path in the rewrite rule..