.htaccess file not found - apache

I got my website done by my friend it is up and running in the public server. I tried to run the same website on my internal server. But apache says file not found. I figured out that the problem is in .htaccess file. This is my file
AddType text/x-component .htc
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
and in my apache conf file I set
<VirtualHost *:80>
DocumentRoot /srv/www/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /srv/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 192.168.43.0/255.255.255.0 192.168.42.0/255.255.255.0
<Directory /srv/www/companies/test1/>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order Allow,Deny
Deny from all
Allow from 192.168.43.0/255.255.255.0 192.168.42.0/255.255.255.0
</Directory>
</Virtualhost>
error log says
[Fri Apr 11 16:57:33 2014] [error] [client 192.168.43.8] File does not exist:/srv/www/cms
[Fri Apr 11 16:57:33 2014] [error] [client 192.168.43.19] File does not exist:/srv/www/products, referer: http://192.168.43.8/companies/
I guess htaccess is lokking for index.php in /srv/www/ folder instead of /srv/www/companies/test1/ folder. Any suggestion how to direct htaccess in correct location?

Assuming you have a cms and product directory in /srv/www/companies/test1/ instead of /src/www/ you could fix the issue by changing your DocumentRoot /srv/www/ to DocumentRoot /srv/www/companies/test1/ and restarting apache.
Generally though, you'd want to set up a custom VirtualHost for each site you are planning on serving and leave the default <VirtualHost *:80> set to whatever should be served by default when you visit your IP address.
See VirtualHost Examples for some examples of common setups.

the .htaccess file is located in the root folder of your instalation and by default is hidden.
If you are using FileZilla:
Start FileZilla then select the "Server" menu at the top
Select "Force showing Hidden Files"

Related

How to fix " Not found " when refresh page with vue js SPA in Apache Server?

I just deploy my vue js project to apache server. My file /dist located in /var/www/html/dist. When i visit the page it's work fine. But when i visit in another page and i refresh the page, in browser say 404 Not found. How can i fix this ?
You need a configuration something similar to this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
It will automatically serve index.html file for every request that doesn't have a corresponding static file. You will have to put this .htaccess file. The use of IfModule is explained here.
I have same error, on ubuntu after i install apache.
First i added in /etc/apache2/apache2.conf
AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In /etc/apache2/sites-available
<VirtualHost test.ru:80>
ServerName www.test.ru
ServerAlias test.ru
ServerAdmin webmaster#localhost
DocumentRoot /var/www/test.ru
<Directory /var/www/test.ru>
#Разрешение на перезапись всех директив при помощи .htaccess
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then in console activate rewrite module and restart apache
sudo a2enmod rewrite
service apache2 restart

Setup subdirectory redirect to a Laravel project

I have three projects, First one is a static html website and other 2 projects are Laravel projects.
I have an SSL certificate set up for the main website. I want to setup the other Laravel projects as subdirectories of the main URL.
I added an alias to my conf file, but it doesn't work. I get this error: "Too many redirects occurred trying to open “https://example.com/admin/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page."
Are there any changes that I should add to htaccess file?
Here is my website.conf file
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/***********.crt
SSLCertificateKeyFile /etc/apache2/ssl/*********.key
SSLCertificateChainFile /etc/apache2/ssl/*********.crt
ServerAdmin admin#example.com
DocumentRoot /var/www/html/example/public_html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /admin "/var/www/html/admin"
<Directory "/var/www/html/admin">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Alias /admin2 "/var/www/html/admin2"
<Directory "/var/www/html/admin2">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I would suggest taking a look at Vagrant with Laravel Homestead prebuilt box. This will achieve what you want to do by editing the Homestead.yaml file, the /etc/hosts file, and then provisioning the vagrant machine. You will need virtual box installed to work with vagrant. You can SSH into the machine by typing vagrant ssh inside the homestead directory.
Documentation: https://laravel.com/docs/5.4/homestead
YouTube Video about Vagrant: https://www.youtube.com/watch?v=LyIyyFDgO4o
Youtube Videos about Installing Laravel Homestead: https://www.youtube.com/watch?v=tbPGuikTzKk&list=PLfdtiltiRHWEaImCreOC7UkK4U5Xv9LdI
You should use the public folder as your alias in the apache setup.
Try "/var/www/html/admin2/public" and also for the Directory as well.
Something like this:
Alias /admin2 "/var/www/html/admin2/public"
<Directory "/var/www/html/admin2/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Depends on the installation of Laravel, you should have an .htaccess file in the public directory, which might require some additional tweeking.
Also, restart apache once you have made the change.t
You need to correctly set 2 things :
Your sites's alias in WAMP's alias folder e.g. C:\wamp\alias to redirect URL to public\index.php in Laravel's folder
Rewrite base .htaccess in your Laravel's public folder so that Apache rewrites on top of a base path.
Assuming that your site's directory is in C:\wamp\www\site and your alias is localhost/alias
Setting alias to point to public folder:
Alias /site "/var/www/site/public"
<Directory "/var/www/site/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Add RewriteBase in .htaccess in Laravel's public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase '/site/'
# 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>

.htaccess RewriteRule php redirect folder to another

I have a folder test. If a person navigates to the folder test, I want the browser to display new.
The folder new doesn't exist on the server, I just want it to be displayed as new, which on the server is linked to the folder test.
This is my config (httpd-vhosts.conf):
<VirtualHost server.com>
DocumentRoot "c:/www/"
ServerName server.com
Alias /new "c:/www/test"
<Directory "c:/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
So, to be clear, if someone browses to:
server.com/test (the server uses folder test, but server.com/new is shown in the browser.
server.com/ (the same as above => server.com/new is shown in the browser)
server.com/index.php (the server uses index.php from folder test, browser shows server.com/new/index.php
server.com/test/index.php (the same as above)
server.com/test/folder2/index.php?variable=1 (the server uses index.php from folder test/folder2 and gives the variables to the php file. browser shows server.com/new/folder2/index.php?variable=1)
I have tried different .htaccess rewrites, but I can't get it working.
Maybe I don't have to use the alias?
Don't just give me a link to the apache manual, because I've read it, but can't get it to work...
You don't need Alias for this so comment out:
Alias /new "c:/www/test"
Then have these rules:
<VirtualHost server.com>
DocumentRoot "c:/www/"
ServerName server.com
<Directory "c:/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^/?$ /new/ [L,R=301]
RewriteCond %{THE_REQUEST} \s/+test(\S*)\s [NC]
RewriteRule ^ /new%1 [R=301,NE,L]
RewriteRule ^/?new(/.*)?$ /test$1 [L,NC]
</VirtualHost>

.htaccess file on the localhost

I am trying rewrite my url by .htaccess file. I tried to find out solution before I ask but nothing to seem work. Could you please help out? Thank you.
Here is my .htaccess file (In the root folders):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
RewriteRule ^film/([^/]*)/([^/]*)\.html$ /html/movie/film.php?film=$1&genreID=$2 [L,QSA]
</IfModule>
I did set these lines (in etc/apache2/sites-available/ 000-default.conf):
DocumentRoot /var/www
<Directory "/var/www/html/movie">
AllowOverride All
</Directory>
I am using Linux mate Apache 2.4.7 and in error.log is nothing wrong.
Do you allow mod_rewrite in php.ini?
You have an .htaccess in the document root folder, which is /var/www according to 000-default.conf.
But you don't allow .htaccess files in /var/www. You allow .htaccess files in /var/www/html/movie, again according to 000-default.conf.
To allow .htaccess files in /var/www or /var/www/html, you must say so, e.g.
<Directory /var/www>
AllowOverride All
</Directory>
or
<Directory /var/www/html>
AllowOverride All
</Directory>
N.B. you don't need AllowOverride All, AllowOverride FileInfo is sufficient for using mod_rewrite, see AllowOverride

How to redirect index.php to / using 301 redirect on apache2 Webserver

I am trying to redirect the index.php to /, at the Document root: /var/www/ by configuring the /etc/apache2/sites-enabled/000-default file.
Using Ubuntu 14.04 Server with apache2.
These are the contents of the Directory directive at /etc/apache2/sites-available/000-default:
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
This is what I've tried from another question here:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
RewriteCond %{THE_REQUEST} ^/index.php$
RewriteRule $(.*)^ / [R=301,L]
</Directory>
I've even tried this RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L], and also RedirectMatch 301 ^/index.php$ http://www.example.com (this time I removed, the RewriteCond).
What happens
I can normally access my site from /, but when I add /index.php I get redirected to wwww.mydomain.com (notice the 4 ws).
What am I doing wrong?