I have a working project with Symfony2.
One of my bundles works well by default but when I activate mod_rewrite I get
This script is only accessible from localhost
This happens only with the routes configured on this bundle, others work fine with mod_rewrite
Here is my vhost config
<VirtualHost *:80>
ServerName my_application.my_domain.net
ServerAdmin xxx#xxx.xxx
DocumentRoot "/var/www/my_application/web"
<Directory /var/www/my_application/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
Where can that come from ?
Update
Example
I'm getting the error when trying to access
my_application.my_domain.net/config/list/produit
If I disable mod_rewrite I can access
my_application.my_domain.net/app.php/config/list/produit
Are you hitting app_dev.php or config.php?
By default, both of those restrict connections from anywhere but localhost and display that exact same message.
Update
After the update, I think the problem may be because you have MultiViews enabled. MultiViews can try to load config.php even if it is just referenced as config. Try removing that and see if it helps improve anything.
Related
I know, there are thousands of .htaccess topics out there but I'm looking for days now and can't find an answer.
I want to use .htaccess to redirect from e.g. https://myserver.com/project/about to https://myserver.com/project/about.php using mod_rewrite.
Project structure
in my /var/www/project folder there is
an about.html containing nothing more than a simple <h1> Header
a .htaccess file containing
RewriteEngine on
RewriteRule ^about$ about.html [NC]
I can access the file with https://myserver.com/project/about.php.
What I've tried so far
I've looked at my /etc/apache2 folder (I'm running an ubuntu server, apache v. 2.2.22).
In the internet I've found I should add AllowOverwrite All somewhere but I couldn't find out where. I've found alot of places where it should go in the internet and tried most of them - without success.
Somehow my files all differ from others.
I've also tried to write in the first line of my /var/www/project/.htaccess deny from all or just random things to see if an error 500 gets printed. Nope. No feedback from my .htaccess at all.
Files
/etc/apache2/..
apache2.conf: Containing no <Directory> tag.
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
</Files>
httpd.conf: Empty.
conf-available/php5.6-fpm.conf: Containing no <Directory> tag.
sites-available/default: Empty.
sites-enabled/default.conf:
<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
sites-enabled/ssl.conf:
<VirtualHost *:443>
...
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
...
</VirtualHost>
I hope you can help me because I literally have no single idea anymore.
I've deployed a new laravel installation to my server, While doing so I configured my apache2 as following:
I added 000-default.conf file in /etc/apache2/sites-available/ as following:
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
I've my laravel installed into /var/www/html/stellar folder now I access my installation through:
http://52.39.175.55/stellar/public/
But while calling the routes it is not working, Like
http://52.39.175.55/stellar/public/oauth/token
Here is the screenshot:
But suppose I call through this:
http://52.39.175.55/stellar/public/index.php/oauth/token
I get the access,
I tried changing my public/.htaccess file to something like this:
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /stellar
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
Still there is no change, Help me out in this.
Your VirtualHost on /etc/apache2/sites-available/ should look like this:
<VirtualHost *:80>
DocumentRoot "/var/www/html/stellar/public"
ServerName yourdomain.com
<Directory /var/www/html/stellar/public>
AllowOverride All
</Directory>
</VirtualHost>
Then restart apache2 and it should work.
I hardly recommend you to duplicate the 000-default.conf file, rename it and include the VirtualHost, then enable it with a2ensite command, just because it's more easy to manage.
We have a problem with access to multiple Symfony3 projects that are in different folders and targeted to the same IP address but in different ports on EC2, for example:
project1:
52.1.1.1:8080/login
/var/www/html/projects/project1/
project2:
52.1.1.1:8181/login
/var/www/html/projects/project2/
Happens that when entering the Project 1 (52.1.1.1:8080) it is displayed correctly, but afterward when accessing to Project 2 (52.1.1.1:8181), this fails, strangely deploys the information from Project 1.
In another scenario, when rebooting the apache service and entering the Project2 (52.1.1.1:8181) all is displayed correctly, but if after entering in the Project2, we enter the Project 1 (52.1.1.1:8080) the information from Project2 is displayed, instead of that of the Project 1.
Ports 8080 and 8181 are open.
Apache configuration on the server is the following:
Listen 8181
<VirtualHost *:8181>
DocumentRoot "/var/www/html/projects/project1/web"
DirectoryIndex app.php
<Directory "/var/www/html/projects/project1/web">
Require all granted
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
<Directory /var/www/html/projects/project1>
Options FollowSymlinks
</Directory>
<Directory /var/www/html/projects/project1/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
CustomLog /var/www/html/projects/project1/var/logs/reg-access.log combined
ErrorLog /var/www/html/projects/project1/var/logs/reg.error.log
</VirtualHost>
Listen 8080
<VirtualHost *:8080>
DocumentRoot "/var/www/html/projects/project2/web"
DirectoryIndex app.php
<Directory "/var/www/html/projects/project2/web">
Require all granted
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
<Directory /var/www/html/projects/project2>
Options FollowSymlinks
</Directory>
<Directory /var/www/html/projects/project2/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
CustomLog /var/www/html/projects/project2/var/logs/reg-rm.log combined
ErrorLog /var/www/html/projects/project2/var/logs/reg.error.log
</VirtualHost>
Any help or ideas about what happens?
UPDATED
To access the Project 1, logs the following error:
[2016-08-17 07:33:12] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Error: Cannot redeclare class Doctrine\Common\Annotations\Annotation\Target" at /var/www/html/projects/project2/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php line 31 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 0): Error: Cannot redeclare class Doctrine\Common\Annotations\Annotation\Target at /var/www/html/projects/project2/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php:31)"} []
"Vendors" is referenced strangely to another project
I found a temporary solution, I had to modify the "app/autoload.php" file
Before
$ loader = require __DIR__.'/../vendor/autoload.php';
After
$ loader = require __DIR__.'/../../project1/vendor/autoload.php';
And it all worked properly.
But I communicated with Javier Eguiluz and he suggested to try installing APC on the server, I installed it, rolled back the changes to the file "app/autoload.php" and it worked properly.
EDIT #2 based on your comment.
Listen 8181
<VirtualHost *:8181>
Servername project1.com
...
Listen 8080
<VirtualHost *:8080>
Servername project2.com
DocumentRoot "/var/www/html/projects/project2/web"
DirectoryIndex app.php
On a remote host edit your hosts file to include the above host names.
For example, if you are on a remote Windows host, edit the file "c:\Windows\System32\Drivers\etc\hosts" as follows:
52.1.1.1 project1.com
52.1.1.1 project2.com
Then in your browser use:
http://project1.com:8181
http://project2.com:8080
This should work. Please investigate first before downvoting. Thanks!
My current .htaccess file looks like this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have laravel 4 installed on an ubuntu 14.04 distribution.
My apache.config file looks like this:
<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And my 000-default.config is as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/public
<Directory /var/www/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Laravel's installed in /var/www
What I experience however is that when I try to navigate to the IP of the site (no domain attached). I get redirected to www.ip_address
for example 178.1.2.3 would have me redirect to www.178.1.2.3.
Mod_rewrite is enabled. So I have no idea why this is happening.
Could anybody help?
Thanks
If it's redirecting, so it's not rewrite problem, the problem with redirecting.
If You navigate to: http://178.1.1.1 and as result You're in http://www.178.1.1.1 so it means in Your code somewhere redirection happens.
it's not apache issue, it's in laravel app code.
To prove it You can put in /var/www/public/index.php after <?php:
die($_SERVER['REQUEST_URI']);
it will show You that web server rewrites properly.
You've to find such code where it redirects and comment it.
Normal app must not redirect to www.HOSTNAME, redirection must be in web server level, not in app level.
I have just configured my LAMP stack on my Ubuntu 14.04 distribution and want to set .htaccess up to serve a website.
I followed the tutorial https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file and configured a virtual host for my domain, however I am still unable to use the .htaccess file in my projects root, whenever I try to serve a page I get a 404 error.
The .conf file for my domain looks like:
<VirtualHost *:80>
ServerAdmin alexmk92#live.co.uk
ServerName alexsims.me
ServerAlias www.alexsims.me
DocumentRoot /var/www/alexsims.me
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/alexsims.me>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I tried to change AllowOverride None to AllowOverride All but that caused an internal 500 error even after enabling mod_rewrite.
Regards,
Alex.
EDIT: .htaccess contents
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^alexsims.me [NC]
RewriteRule ^(.*)$ http://www.alexsims.me/$1 [L,R=301,NC]
#--- Rewrite PHP files clean URL
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)$ ?page=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ ?page=$1&id=$2 [NC,L]
I have same issue with Ubuntu 15.10.
I solved this way.
First you need to enable rewrite module:
sudo a2enmod rewrite
sudo gedit /etc/apache2/apache2.conf
and replace
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
With:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And finally
sudo service apache2 reload
Actually what is difference between restart and reload !
restart= stop + start
reload = remain running + re-read configuration files.
We have changed configuration so we need to reload configuration.
It should help someone as I have wasted 4 hours :)
Try
Require all granted
in place of
Order allow,deny
allow from all
See the upgrade documentation for more info:
In 2.2, access control based on client hostname, IP address, and other
characteristics of client requests was done using the directives
Order, Allow, Deny, and Satisfy.
In 2.4, such access control is done in the same way as other
authorization checks, using the new module mod_authz_host. The old
access control idioms should be replaced by the new authentication
mechanisms, although for compatibility with old configurations, the
new module mod_access_compat is provided.
AllowOverride None
That's your problem, right there. The 500 error you're getting could mean that your .htaccess file is malformed - start
See http://httpd.apache.org/docs/current/mod/core.html#allowoverride
You should check if the directives you use in .htaccess are enabled.
For example if you use RewriteEngine you should have apache module rewrite enabled:
cat /etc/apache2/mods-available/rewrite.load
a2enmod rewrite
service apache2 restart
For ExpiresActive directive you should enable apache module expires:
cat /etc/apache2/mods-available/expires.load
a2enmod expires
service apache2 restart
etc.