I am getting a weird issue i created a vhost in lamp stack. The problem is that when I open the vhost site www.domain.com the home page loads without any issue.
But when I use the nav bar to open another page I get a "404 NOT FOUND" i.e www.domain.com/about
But as soon as I put the extension of the file manually the page loads.
www.domain.com/about.php
How can I solve this issue. I am using .htaccess to hide the extension of the file.
Note:
1) All the other local file running properly i.e. I have a wordpress site that works fine (This means the mysql db is not causing the error)
2) The vhost is set properly bcus the terminal did not show any error when the vhost was enabled.
But the vhost in wamp does not give me any kind of issue in my windows 8.1 pro.
Edit :
Code in .htaccess to hide extension this works in my windows pc without any problem.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
EDIT -2
<VirtualHost *:80>
<Directory /var/www/stab-website>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
DocumentRoot "/var/www/stab-website"
ServerName stab-site.com
ServerAlias www.stab-site.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Still did not worked.
You need to enable the MultiViews options:
<VirtualHost *:80>
<Directory /var/www/htdocs>
Options Indexes FollowSymLinks MultiViews
</Directory>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/var/www/htdocs"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
</VirtualHost>
This can either be done in your httpd.conf file, in the configuration file for your virtual host or in a .htaccess file.
You should also make sure so that the mod_negotiation module is enabled. This can be done by running:
sudo a2enmod negotiation
You also might need to verify that your virtual host configuration is fine, this can be done from the terminal using:
apache2ctl -t
After this you need to restart your server:
sudo service apache2 restart
From the documentation:
The effect of MultiViews is as follows: if the server receives a
request for /some/dir/foo, if /some/dir has MultiViews enabled, and
/some/dir/foo does not exist, then the server reads the directory
looking for files named foo.*, and effectively fakes up a type map
which names all those files, assigning them the same media types and
content-encodings it would have if the client had asked for one of
them by name. It then chooses the best match to the client's
requirements.
Thanks #Cyclone for your help
This post helped me to fix this issue
https://askubuntu.com/questions/233046/how-to-give-my-user-permission-to-add-edit-files-on-local-apache-server
The post above help to run Apache server as the logged in user.
To give rights to use .htaccess --
First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/wwws
And also don't forget to add this code in the apache2.conf
<Directory /var/www/ProjectRootDirectory>
AllowOverride All
</Directory>
Related
After successfully installing the dependencies for Akeneo and the Akeneo pim-community-standard on a Debian 9 machine, I can open the login screen in the frontend on http://myhost.net/app.php
The Login process throws a 404 error on http://myhost.net/form/extensions.
This should be a JSON file (like it is on the demo installation of Akeneo), but it was not built in the installation process. Also when I manually create this file the login process goes on to the next 404:
myhost.next/localization/format/date
myhost.next/rest/security/
myhost.next/rest/user/
Which part of the installation process is supposed to build these files?
http://myhost.net/form/extensions is a call to the Symfony backend so it's not a file to generate during installation.
The 404 error seems linked to the fact that you didn't activate mod_rewrite on your apache configuration.
I add my answer because I lost a lot of time.
Solution for Digital Ocean server
Change vhost file to:
<VirtualHost your_server_ip>
RewriteEngine On
DocumentRoot "/var/www/html/web/"
<Directory /var/www/html/web>
AllowOverride None
Require all granted
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
<Directory /var/www/html/>
Options FollowSymlinks
</Directory>
<Directory /var/www/html/web/bundles>
RewriteEngine Off
</Directory>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
ErrorLog ${APACHE_LOG_DIR}/akeneo-pim_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/akeneo-pim_access.log combined
</VirtualHost>
edit your_server_ip
and load entering ip in a browser (without /web/)
Dear people,
My goal is to set up the apache2's 000-default.conf and the .htaccess in a specific way, so the user will always be redirected to a specific php file (index.php for example) if they (the user) wants to access the web app, which I am building.
Examples :
example-app.local
example-app.local/hello-world
example-app.local/admin.php
example-app-local/../../../../my-passwords.txt
All of them should point to index.php. I followed several tutorials, but I guess I need a specific tutorial for me, so that I can fully understand the concepts of apache2 and its configurations. Feel free to judge me - I am alright with criticism.
What I have in my files is the following
1. The 000-default.conf file which is located in /etc/apache2/sites-available/
<VirtualHost *:80>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
...and loads of comments
2. The example-app.local.conf file which is located in /etc/apache2/sites-available/
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example-app.local
ServerAlias www.example-app.local
DocumentRoot "/var/www/example-app"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
3. The .htaccess file which is located in /var/www/example-app/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,R]
What I get is the following : "Apache default conf is like a god of the configurations and you can state specifically that you can AllowRedirect which will magically trigger the functionality of htaccess and there you need the even more magical syntax to make every request from the user point ONLY to the index.php" Is this correct?
What is working Apache is working. I am enabling and disabling configs via
sudo a2ensite 000-default.conf
sudo a2dissite 000-default.conf
and then I restart and check that everything is fine via
sudo service apache2 restart
sudo service apache2 status
the status states active (running).
The content of /etc/hosts is also edited in a correct way, because I can actually see the content of the index.html file when I try to point my browser to the example-app.local page. I would also like to point out that I have php installed correctly - I tested it via the phpinfo function/method.
I tried several tutorials and none of them helped me. I believe I am missing something important and I am too 'blind' to see it, so I need someone to 'open' my eyes, so please - help me.
Best regards,
Yet another confused startup developer,
Bobkoo
Try tis one:
After RewriteEngine On try RewriteBase / and lose the slash before index.php
BTW you working on Windows... so the DocumentRoot "/var/www/example-app" should be something like C:\xampp\htdocs\project-folder
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.
I have Apache 2.2 configured to run with Coldfusion 9.2, both on the same Centos 6.2. The general config of DocumentRoot in Apache is
DocumentRoot "/var/www/html"
Up until now Apache handed all calls to cfcs and cfms over to Coldfusion. I then created a virtual host
<VirtualHost 192.168.123.207:80>
ServerName myserver.server.private
ServerAlias www.myserver.server.private
ServerAlias webmail.myserver.server.private
ServerAlias admin.myserver.server.private
DocumentRoot /home/myserver/public_html
ErrorLog /var/log/virtualmin/myserver.server.private_error_log
CustomLog /var/log/virtualmin/myserver.server.private_access_log combined
ScriptAlias /cgi-bin/ /home/myserver/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/myserver/public_html>
Options +Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
allow from all
AllowOverride All
Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
<Directory /home/myserver/cgi-bin>
allow from all
AllowOverride All
Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.myserver.server.private
RewriteRule ^(.*) http://myserver.server.private:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.myserver.server.private
RewriteRule ^(.*) http://myserver.server.private:10000/ [R]
</VirtualHost>
When I open a html file on http://myserver.server.private/hello.html, the correct file within the virtual host document root (/home/myserver/public_html) gets served.
Calling a cfm fails though. Apache passes the request on correctly but then a Coldfusion error message shows up:
File not found: /hello.cfm
It seems that Coldfusion is getting the file name, prefixes a wrong directory path to it and fails loading it from the disk.
I scanned all Coldfusion files for a wrong document root but could not find anything.
EDIT
It turns out that Coldfusion looks into it's own webroot directory at
/opt/coldfusion/wwwroot
I placed a file with the same name but different content there and that one gets served, although there is a) a virtual host and b) the general DocumentRoot is set to /var/www/html.
It turns out that the coldfusion user (cfusion in my case) needs to be in the group of the virtual host user.
usermod -a -G newuser cfusion
After a restart of coldfusion, all works.
I'm bulding a RESTful api based on Tonic.
On my developer machine and our stage server we use virtual hosts.
Tonic uses a .htaccess file to translate the incomming calls to it's dispatcher.php file. This works fine on servers without VirtualHosts enabled.
However if i enable VirtualHosts i get a file not found even thought the path and name to the file is correct.
Here is the VirtualHost setup on my developer machine.
<VirtualHost *:80>
ServerAdmin admin#xxxxxxxxxxxx
ServerAlias *.dev.xxxxx
VirtualDocumentRoot /home/xxxxxxxx/workspace/%1
<Directory /home/xxxxxxxx/workspace/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And Tonic's .htacces located in a folder called rest in the project root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !dispatch\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* dispatch.php [L,QSA]
</IfModule>
A call to http://project.dev.xxxxx/rest/ gives:
Not Found
The requested URL /home/xxxxxxxx/workspace/project/rest/dispatch.php was
not found on this server.
Apache/2.2.22 (Ubuntu) Server at xxxxxxx Port 80
It appears as though you're misusing VirtualDocumentRoot. Try changing it to:
DocumentRoot /home/xxxxxxxx/workspace/project/rest
Also, here's a good explanation on the VirtualDynamicRoot: Dynamically configured mass virtual hosting
Hope that helps.