I have been trying, for the good part of two hours, to configure apache2 to use .htcaccess.
Here's my configuration file:
<VirtualHost *:80>
ServerAdmin MY_EMAIL
DocumentRoot /var/www/MY_DOMAIN/public_html
ServerName MY_DOMAIN
ServerAlias www.MY_DOMAIN
Header set Access-Control-Allow-Origin "*"
<Directory /var/www/MY_DOMAIN/public_html>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName SUB_DOMAIN.MY_DOMAIN
DocumentRoot /var/www/MY_DOMAIN/SUB_DOMAIN
<Directory /var/www/MY_DOMAIN/SUB_DOMAIN>
AllowOverride All
</Directory>
</VirtualHost>
And here is my .htcaccess (located in /var/www/MY_DOMAIN/public_html/.htcaccess):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
If I visit MY_DOMAIN/header, I receive a 404 Error. However, MY_DOMAIN/header.php works fine.
How can I fix this? Thanks!
Are you naming the file ".htaccess" or ".htcaccess"
If you are not naming the file properly, that is probably the problem.
I think you're looking for ".htaccess"
Related
I have a beta wordpress site (beta.domain.co.uk) I would like to redirect to (domain.co.uk).
I have a .conf file for each site pointing to its folder with the wordpress files.
I have tried just renaming the folders but I get a 404 error.
How can I point the beta site to my main site?
main site conf :
<VirtualHost *:80>
ServerName www.domain.co.uk
DocumentRoot /var/www/domain.co.uk
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/domain.co.uk/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domain.co.uk
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.co.uk
RewriteRule ^/(.*)$ http://www.domain.co.uk/$1 [L,R=301]
</VirtualHost>
beta site conf:
<VirtualHost *:80>
ServerName beta.domain.co.uk
DocumentRoot /var/www/beta.domain.co.uk
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/beta.domain.co.uk/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Use the following rewrite rules, make sure you put it inside the beta site conf, inside virtualhost.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^beta\.domain\.co\.uk$
RewriteRule ^(.*)$ http://domain.co.uk/$1 [R=301,L]
I have Internal Server Error (error 500):
[client 5.211.29.235:10910] /home/..../public_html/public/.htaccess: Options not allowed here
mysite.conf:
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias mywebsite.com *.mywebsite.com
DocumentRoot /home/..../public_html/public/
ErrorLog /home/..../public/error_log
</VirtualHost>
Changing permission to read-write file(755) did not work.
Disable SELinux did not help.
Changing .httaccess also did not help.
changing httpd.conf did not help too.
<Directory />
AllowOverride ALL
</Directory>
or
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride Options
Order allow,deny
allow from all
</Directory>
change .htaccess did not work:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
problem solved by changing mysite.conf file to this:
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias mywebsite.com *.mywebsite.com
<Directory />
AllowOverride ALL
</Directory>
DocumentRoot /home/..../public_html/public/
ErrorLog /home/..../public/error_log
</VirtualHost>
When I run api.troop37bsa.org/user, I am able to access the page but when I run https://api.troop37bsa.org/user, I get a 404 error. When I run api.troop37bsa.org/?url=user or the secure version I get the correct page.
I am using a .htaccess file to rewrite the url so that everything after the subdomain is considered a parameter string.
So my question is two fold. How can I get https://api.troop37bsa.org/user to work and also what can I do to reduce the size of my .conf file and reduce or merge my .htaccess file.
I have an Apache Server 2.4.18.
My .conf file is setup as follows:
<VirtualHost *:80>
ServerAdmin kreichner#troop37bsa.org
ServerName api.troop37bsa.org
ServerAlias api.troop37bsa.org
DocumentRoot /var/www/troop37bsa.org/api/public
<Directory /var/www/troop37bsa.org/api/public>
DirectoryIndex index.php index.html
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
AccessFileName .htaccess
ErrorLog /var/www/troop37bsa.org/api/public/apache_error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =api.troop37bsa.org
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin kreichner#troop37bsa.org
ServerName api.troop37bsa.org
ServerAlias api.troop37bsa.org
DocumentRoot /var/www/troop37bsa.org/api/public
<Directory /var/www/troop37bsa.org/api/public>
DirectoryIndex index.php index.html
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
AccessFileName .htaccess
ErrorLog /var/www/troop37bsa.org/api/public/apache_https_error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
In my subdomain folder (ie /var/www/troop37bsa.org/api/public) I have an .htaccess file
ReWriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^(.+)$ %2index.php?url=$1 [QSA,L]
I am also using a letsencrypt SSL certificate that otherwise seems to be working fine.
Thanks
As I said in the comment section, It turns out that there was a conf file generated by letsencrypt, but it was pointing to the wrong directory publicl instead of public. When I changed the directory name. the .htaccess file did its job. I also removed the second *.443 virtualHost from my orginal conf to avoid further conflicts.
So others may not fall into the same problem the name of the conf was api.troop37bsa.org-le-ssl.conf. This set up the look ups from the SSL certificate.
the api.troop37bsa.org-le-ssl.conf code is as follows:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin kreichner#troop37bsa.org
ServerName api.troop37bsa.org
ServerAlias api.troop37bsa.org
DocumentRoot /var/www/troop37bsa.org/api/public
<Directory /var/www/troop37bsa.org/api/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/troop37bsa.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/troop37bsa.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
Thank you everyone for your help.
I am using Apache/2.4.7 to host a server. I am hosting phabricator on it.
Let us say that the ip is x.x.x.x and the domain name pointing to the ip is example.com.
Following are the contents of
/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerName http://x.x.x.x/
DocumentRoot /home/ubuntu/phabricator/phabricator/webroot
RewriteEngine on
RewriteRule ^/rsrc/(.*) - [L,QSA]
RewriteRule ^/favicon.ico - [L,QSA]
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA]
<Directory /home/ubuntu/phabricator/phabricator/webroot>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName http://example.com
ServerAlias www.example.com
DocumentRoot /home/ubuntu/phabricator/phabricator/webroot
RewriteEngine on
RewriteRule ^/rsrc/(.*) - [L,QSA]
RewriteRule ^/favicon.ico - [L,QSA]
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA]
<Directory /home/ubuntu/phabricator/phabricator/webroot>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
So, if I enter the ip, i.e., x.x.x.x in the address bar of the browser, phabricator opens up nice and fine. But instead if I use the domain name: example.com,
it throws up the error:
This request asked for "/" on host "placire.com", but no site is configured which can serve this request.
What mistake am I making? How do I go on about resolving it?
Thank you.
PS: I used the follwoing guide for configuring Phabricator:
https://secure.phabricator.com/book/phabricator/article/configuration_guide/
PPS: Also, I'm pretty sure that example.com points correctly to x.x.x.x because using the following conf file , when I enter example.com in the address bar I see the apache default page:
<VirtualHost *:80>
ServerName http://x.x.x.x
DocumentRoot /home/ubuntu/phabricator/phabricator/webroot
RewriteEngine on
RewriteRule ^/rsrc/(.*) - [L,QSA]
RewriteRule ^/favicon.ico - [L,QSA]
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA]
<Directory /home/ubuntu/phabricator/phabricator/webroot>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This link: https://secure.phabricator.com/T8717 gives me a hint that you probably need to set the config parameter phabricator.base-uri. Try:
./bin/config set phabricator.base-uri 'http://example.com/'
The DocumentRoot of example.com is in /var/www/html.
Laravel is installed in /var/www/example/public and I can access it using http://example.com/dashboard but problem arises when I try to access other routes like as http://example.com/dashboard/login and is throwing 404 Not Found error. And saying The requested URL /var/www/example/public/index.php was not found on this server. Can anyone please guide me?
The .htaccess file in the public directory is untouched.
Here is the 000-default.conf:
ServerName example.com
UseCanonicalName Off
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /dashboard /var/www/example/public
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
#dynamic subdomain provisioning
<VirtualHost *:80>
DocumentRoot /var/www/example/public
ServerName user.example.com
ServerAlias *.example.com
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I could solve using the following in the 000-default.conf file:
<Directory /var/www/example/public>
DirectoryIndex index.php
AcceptPathInfo on
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
And had to change the laravel .htaccess in the following way:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /dashboard
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ dashboard/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>