I need help with two .htaccess files - one in root of the webserver and second in subfolder.
.htaccess in root directory is working fine
/var/www
Options +FollowSymLinks MultiViews
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
.htaccess in subdirectory - doesnt work
/var/www/subdirectory
AddType application/x-httpd-php .html
ExpiresActive On
ExpiresDefault A1
Header append Cache-Control must-revalidate
Apache config - I have two virtualhosts - one for 80 and second for 443.
In *80 I have directory options
<Directory /var/www/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
In the subfolder I have .html files and this htaccess should treat them as php. Am I missing something ?
Just a note - whole PHP code is commented in html when I use inspect element.
PHP 5.6 Apache 2.4.0
Ok, I managed to resolve my problem,
missing expire modul
a2enmod expire
Missing the same directive directory in 443 virtualhost
I commented this line Header append Cache-Control must-revalidate
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 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
I am trying to rewrite the url for a rest call (backend written in php).
The problem is, that the .htaccess file is not working, or the file in general is ignored by the server.
What i've tried
I've edited the httpd.conf file and changend following lines:
<Directory />
Options All
AllowOverride All
</Directory>
<Directory "${SRVROOT}/htdocs">
Options All
AllowOverride All
Require all granted
</Directory>
i also added a Directory Tag for my specific folder:
<Directory "${SRVROOT}/htdocs/my/path/backend/">
Options All
AllowOverride All
</Directory>
My .htaccess file looks like this:
#.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L,QSA]
Because i am using the RewriteEngine i had to enable this module in the httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Infos
I'm working on Windows 10 machine.
My Apache version is: 2.4.16 Win32
Problem
The problem is that the server ignores the .htaccess file. I know that because i tried to change the DefaultIndex with following line:
DirectoryIndex startPage.html
without any success.
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"
I've set up a server using PHP5-FPM (using PHP 5.3.27) and apache2.
There is an api.php file in the doc root, and using mod_rewrite i've got this rule in .htaccess:
RewriteEngine on
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
So what i want is for everything except exact file matches to be passed to index.php
What is happening, however, is when i go to /api/ the api.php is being loaded, instead of the request being forwarded to the index.php
I've gone through the documentation, googled thoroughly (unless i'm not using the right keywords), and checked out both the apache and php configuration. This doesn't happen on our live server or our development servers that use a conbination of nginx and php5-fpm or apache and mod_php5
My Apache config for the vhost is:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName admin.localhost
ServerAlias *.localhost
<Directory "/var/www/html">
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
# Wire up Apache to use Travis CI's php-fpm.
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
</IfModule>
</VirtualHost>
EDIT
I've investigated further:
If i remove api.php - the rewrite works
If i remove the RewriteCond %{REQUEST_FILENAME} !-f - the rewrite works
Any .php file they get loaded without the extension - not non-php files only work with the extension.
Try replacing:
Options FollowSymLinks MultiViews ExecCGI
By:
Options FollowSymLinks -MultiViews ExecCGI
The MultiViews keyword comes from mod_negociation and can have a lot of side-effects. One of theses effect is that it can scan for known extensions, when you request 'api' it can scan for api.php' or 'api.html' files and redirect internally the requests on theses files.
From http://httpd.apache.org/docs/2.2/content-negotiation.html#multiviews :
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.
To me this seems like a big hole, some considers it a feature.