The error in browser I get is:
The requested URL /home/user/public_html/some_folder was not found on this server.
And the apache log is:
[Sat Aug 17 20:57:57 2013] [error] [client ] File does not exist: /var/www/html/home
So naturally I think, I'll try RewriteBase /../../../home/user/public_html/, but that gives me:
[Sat Aug 17 20:59:22 2013] [error] [client ] Invalid URI in request GET /~user/ HTTP/1.1
How do I get around this?
The .htaccess is simple:
RewriteEngine On
RewriteBase /../../../home/user/public_html/
RewriteRule index.php some_folder/index.html [L]
You could use a symlink.
cd /var
cp /var/www /var/backup_www
rm -rf /var/www
ln -s /home/user/public_html/ www
And enable following symlinks in your httpd.conf.
<Directory /var/www>
Options FollowSymLinks
</Directory>
<Directory /home/user/public_html>
Options -FollowSymLinks
</Directory>
Alternatively, just change the DocumentRoot for the server/vhost.
Related
I have a VPS running Apache as webserver and serving requests for a certain domain and related subdomains.
For each of these domain/subdomains, I have configured the redirection from HTTP to HTTPS, in this way:
<IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName sub.domain.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =sub.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName sub.domain.com
DocumentRoot /var/www/html/sub.domain.com
[...]
This configuration seems to work properly for all the domains, except for the one dedicated to SMTP (stmp.domain.com) for which the response seems to failback to the default configuration (and so, to the index.html file located in /var/www/html/); then, only the explicit HTTPS request seems to work fine, in that case.
How is this possible? Maybe are there some configuration files which overwrite that configuration? If yes, what should I check, in theory? For the apache2ctl configtest command, everything is okay.
Oct 23rd Update
As suggested in the comments, I activated the log for the rewrite module, by adding this line to apache2.conf file:
LogLevel alert rewrite:trace6
I then tried to make a couple of HTTP requests to two different endpoints of the server and I compared what was going on via the logs. It seems that the rewrite rule is not reached for smtp.domain.com since I found only this print into the access.log file:
[23/Oct/2022:11:46:29 +0000] "GET / HTTP/1.1" 403 440 "-" "curl/7.68.0"
For the other configurations I confirm the rewrite rule works properly because I can see several prints in the log. For instance, for imap.domain.com I found this inside error.log:
[Sun Oct 23 11:39:09.846013 2022] [rewrite:trace3] [pid 2390:tid 140516244342528] mod_rewrite.c(483): [client MY_IP_ADDR] MY_IP_ADDR - - [imap.domain.com/sid#7fcc7e661df0][rid#7fcc7c4ec0a0/initial] applying pattern '^' to uri '/'
[Sun Oct 23 11:39:09.846144 2022] [rewrite:trace4] [pid 2390:tid 140516244342528] mod_rewrite.c(483): [client MY_IP_ADDR] MY_IP_ADDR - - [imap.domain.com/sid#7fcc7e661df0][rid#7fcc7c4ec0a0/initial] RewriteCond: input='imap.domain.com' pattern='=imap.domain.com' => matched
[Sun Oct 23 11:39:09.846166 2022] [rewrite:trace2] [pid 2390:tid 140516244342528] mod_rewrite.c(483): [client MY_IP_ADDR] MY_IP_ADDR - - [imap.domain.com/sid#7fcc7e661df0][rid#7fcc7c4ec0a0/initial] rewrite '/' -> 'https://imap.domain.com/'
[Sun Oct 23 11:39:09.846182 2022] [rewrite:trace2] [pid 2390:tid 140516244342528] mod_rewrite.c(483): [client MY_IP_ADDR] MY_IP_ADDR - - [imap.domain.com/sid#7fcc7e661df0][rid#7fcc7c4ec0a0/initial] explicitly forcing redirect with https://imap.domain.com/
[Sun Oct 23 11:39:09.846200 2022] [rewrite:trace1] [pid 2390:tid 140516244342528] mod_rewrite.c(483): [client MY_IP_ADDR] MY_IP_ADDR - - [imap.domain.com/sid#7fcc7e661df0][rid#7fcc7c4ec0a0/initial] redirect to https://imap.domain.com/ [REDIRECT/301]
The main concern is that actually the configuration of smtp.domain.com differs from the one of imap.domain.com only by server name. Here is the result of git diff:
diff --git a/smtp.domain.com.conf b/imap.domain.com.conf
index f7778ee..cba26cb 100644
--- a/smtp.domain.com.conf
+++ b/imap.domain.com.conf
## -1,27 +1,20 ##
<IfModule mod_ssl.c>
<VirtualHost *:80>
- ServerName smtp.domain.com
+ ServerName imap.domain.com
RewriteEngine on
- RewriteCond %{SERVER_NAME} =smtp.domain.com
+ RewriteCond %{SERVER_NAME} =imap.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
- ServerName smtp.domain.com
- DocumentRoot /var/www/html/smtp.domain.com/
+ ServerName imap.domain.com
+ DocumentRoot /var/www/html/imap.domain.com/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
Furthermore, in the main configuration file I didn't find any mention to smtp.domain.com so I suppose there is not any rule which overwrites the one in the domain configuration.
Oct 23rd Further Update
It seems that for requests to http://smtp.domain.com Apache uses the default configuration file (000-default.conf) instead of the custom one (smtp.domain.com.conf) which I reported here. In fact, by adding the same rewrite rule in the first one, the redirection works properly. Any of you can maybe explain me what is going on and why? Why are HTTP requests not managed via the custom configuration, even if there is a related branch of rules?
I want to solve or disable this error:
[Thu Jan 02 23:48:06.382888 2020] [autoindex:error] [pid 17460:tid 140351947863808] [client 92.36.xxx.xxx:49018] AH01276: Cannot serve directory /home/user/public_html/kodi/repository/: No matching DirectoryIndex (index.php,index.html.var,index.htm,index.html,index.shtml,index.xhtml,index.wml,index.perl,index.pl,index.plx,index.ppl,index.cgi,index.jsp,index.js,index.jp,index.php4,index.php3,index.phtml,default.htm,default.html,home.htm,index.php5,Default.html,Default.htm,home.html) found, and server-generated directory index forbidden by Options directive
Folder repository doesn't have any index or .htacess file.
I need this folder without index file.
I have apache 2.4 and this config:
<Directory "/home/user/public_html/kodi/">
Require all granted
</Directory>
<Directory "/home/user/public_html/kodi/repository/">
Require all granted
</Directory>
How to solve this error?
I solved this error.
I deleted code above, and enter this:
<Directory "/home/user/public_html/kodi">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Also deleted .htaccess in kodi folder.
And made default.php empty file and now all works great!
I am having issue while setting up virtual localhosts in my httpd.conf. What i write
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/Users/user/Documents/dispatcher/cache"
<Directory C:/Users/user/Documents/dispatcher/cache>
<IfModule disp_apache2.c>
SetHandler dispatcher-handler
ModMimeUsePathInfo On
</IfModule>
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
My apache version is 2.2.21. Error is :
[Mon Jan 25 22:46:17 2016] [error] [client 127.0.0.1] Attempt to serve directory: C:/Users/user/Documents/dispatcher/cache/
I have to following problem. After installing RewriteEngine on my Apache server by sudo a2enmode rewrite && service-apache restart I am getting a 403 Permission Error, when trying to access the Website. The error log reads:
[Mon Aug 03 16:47:04.772033 2015] [authz_core:error] [pid 27107] [client ::1:41610] AH01630: client denied by server configuration: /home/lenxn/Venuzle/vvm/public/
The access log:
::1 - - [03/Aug/2015:17:08:11 +0200] "GET / HTTP/1.1" 403 2267 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.8.0"
The apache2.conf remained unaffected from the installation and the .htaccess in my source root directory looks like:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
What is the problem here? I have been able to access the server previous to the installation. Have there been any files created or alternated, which overrule my previous permission settings?
I finally fixed it by altering the section
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
from the apache2.conf to
<Directory />
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory> .
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"