apache httpd is automatically redirecting to https - apache

Server is running on RHEL 7.9, httpd 2.4.6 and I have the following structure in my /var/www/html directory:
/site
index.php
I can reach the root index.php by visiting the IP address. However, when I try to access content inside /site directory, it automatically switches to https, hence the content does not load.
Some snippets from /etc/httpd/conf/httpd.conf:
DocumentRoot "/var/www/html"
<Directory />
AllowOverride None
Require all denied
Options -Indexes +FollowSymLinks
</Directory>
<Directory "/var/www/html">
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
<Directory "/var/www/html">
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
AccessFileName .htaccess
<IfModule dir_module>
DirectoryIndex index.php index.htm index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
IncludeOptional conf.d/*.conf
I have a virtual host setup for /etc/httpd/conf.d/site.conf
<VirtualHost <server ip>:80>
ServerAdmin webmaster#sitename.com
DocumentRoot /var/www/html/site/
ServerName www.sitename.com
ServerAlias sitename
<Directory /var/www/html/site>
Require all granted
</Directory>
</VirtualHost>

Related

Htaccess issue with RewriteOptions InheritBefore

I have got two htaccess:
api/public/.htaccess
RewriteRule . index.php
api/public/cron/web/.htaccess
RewriteEngine On
RewriteOptions InheritBefore
I set my vhost for cron:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName cron.api.local
ServerAlias www.cron.api.local
DocumentRoot /var/www/api/public/cron/web
ErrorLog ${APACHE_LOG_DIR}/api_cron_error.log
CustomLog ${APACHE_LOG_DIR}/api_cron_access.log combined
<Directory "/var/www/api/public/cron/web">
Options Indexes FollowSymLinks MultiViews
Require all granted
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Url http://cron.api.local/up returns 404 status but when i replace RewriteOptions InheritBefore with RewriteRule . index.php then it works. What is wrong?
I use apache 2.4.18 and ubuntu 16.04.
To fix this issue follow this:
sudo nano /etc/apache2/apache2.conf
Find:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted </Directory>
Replace With:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Exit and save and restart apache with command
sudo systemctl restart apache2
Reverence:
Apache mod_rewrite is enable on server but not working?

rancid VIEWVC apache rewrite rule, CGI page incorrectly shown

i configured rancid VIEWVC web page, CentOS 8
<VirtualHost *:80>
DocumentRoot /var/www
ScriptAlias /cgi-bin/ "/var/www/cgi-bin"
ScriptAlias /viewvc /var/www/cgi-bin/viewvc.cgi
ScriptAlias /query /var/www/cgi-bin/query.cgi
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
It works fine when accessing http://ip/viewvc
I want to access to VIEWVC page by http://ip
so i modified conf file:
<VirtualHost *:80>
DocumentRoot /var/www
ScriptAlias /cgi-bin/ "/var/www/cgi-bin"
ScriptAlias /viewvc /var/www/cgi-bin/viewvc.cgi
ScriptAlias /query /var/www/cgi-bin/query.cgi
RewriteEngine on
RewriteRule (.*) /var/www/cgi-bin/viewvc.cgi
<Directory "/var/www/cgi-bin">
AllowOverride All
Options +ExecCGI -Indexes
AddHandler cgi-script cgi py
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
with redirection, page is "partially" loaded
http://IP
Without redirection all works fine
http:/ip/viewvc
Try at least RewriteRule ^/$ instead otherwise any static assets will be rewritten to the CGI too.

External access web page with VirtualHosts and Wampserver

I am a newbie in wampserver.
I installed it and I can acesss web pages with localhost port 8000 without problems. Yes, I changed default port to 8000 and all works well with localhost.
Now, I created a simple project web page and I need external access. Here is my settings:
But I get the next error when I try to acesss remotely:
Forbidden
You don't have permission to access / on this server.
Apache/2.4.23 (Win64) PHP/5.6.25 Server at agenda.myvnc.com Port 8000
//agenda.myvnc.com is my elastic IP host server
My sample project:
Folders:
c:\wamp64\www
...........cloudappoint.myvnc.com(subfolder in www)
File in cloudappoint.myvnc.com folder: index.php
NOIP DNS:
- Host:cloudappoint.myvnc.com
- Target IP:XXX.XXX.XXX:8000(My host is located at amazon ec2 with elastic ip- XXXX.XXX.XXX)
- type:URL
WampServer VirtualHosts:
<VirtualHost *:8000>
ServerName cloudappoint.myvnc.com
DocumentRoot c:/wamp64/www/cloudappoint.myvnc.com
ErrorLog "logs/agenda-error.log"
CustomLog "logs/agenda-access.log" common
<Directory "c:/wamp64/www/cloudappoint.myvnc.com">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EDITED: Here is my complete Virtual hosts file:
<VirtualHost *:8000>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:8000>
ServerName cloudappoint
ServerAlias cloudappoint.myvnc.com
DocumentRoot c:/wamp64/www/webagenda
ErrorLog "logs/agenda-error.log"
CustomLog "logs/agenda-access.log" common
<Directory "c:/wamp64/www/webagenda/">
Options +Indexes +FollowSymLinks +MultiViews
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I am unable to acesss remotely cloudappoint.myvnc.com, but if I move
<Directory "c:/wamp64/www/webagenda/">
Options +Indexes +FollowSymLinks +MultiViews
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
out from VirtualHost, all works well. Then, I guess 3.06 has broken Directory into Virtual Hosts.

Configuring apache to deny traversing to seperate domains

So, I have just found something I've missed about Apache ...
I have 3 sites:
/var/www/site1files (www.site1.com)
/var/www/site2files (www.site2.com)
/var/www/site3files (www.site3.com)
Each have an index.html ...
Now, when I go to each site, they work as expected ...
But, if I go to www.site1.com/site2files/index.html, strangely, it brings up that file (www.site2.com/index.html) ... Surely there's something really wrong I've done with my configuration ...
apache.conf (all default with):
<Directory /var/www/site1>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/site2>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/site3>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
And each has a conf file in enabled-sites:
<VirtualHost *:80>
ServerAdmin admin#site1.com
ServerName site1.com
ServerAlias www.site1.com
DirectoryIndex index.html
DocumentRoot /var/www/site1
<Directory /var/www/site1>
Options +FollowSymLinks -MultiViews -Indexes
AllowOverride None
Order allow,deny
allow from all
Require all granted
ErrorDocument 403 /404.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
</Directory>
</VirtualHost>
Okay, it seems I was confused about how to set up apache ...
I removed the site1,site2 and site3 <Directory> blocks from the apache.conf file, and just left the conf files in enabled sites ... Kinda makes sense now that I think about it ...
Remedial apache documentation reading for me ...

Trying to do hidden redirect with .htaccess - redirect is visible

I am trying to set something up on my local server where if I go to mydomain/docs it does a redirect internally to mydomain/slate/build, but have the user still see mydomain/docs in their browser's url. I have it half working - when I go to mydomain/docs, it loads the correct index.html in /slate/build but the issue is that my url bar:wq shows mydomain/slate/build when the desired url is mydomain/docs.
Here is my entire .htaccess file that does the redirect:
RewriteEngine on
RewriteRule ^/?docs$ /slate/build [L]
And here is what I believe to be potentially relevant from my apache2.conf:
HostnameLookups Off
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
And finally my VirtualHost in sites-enabled:
<VirtualHost mydomain>
DirectoryIndex index.html
ServerAdmin postmaster#dummy-host.localhost
DocumentRoot /correct/file/structure
ServerName mydomain
ServerAlias mydomain
</VirtualHost>
Yes it is - it's a directory with an index.html in it, which is the file I'm trying to pull up.
Since it's a directory, you need to end the URI with a slash, otherwise mod_dir will kick in an redirect the browser to the same URI but with a trailing slash. Try changing your rule to:
RewriteEngine on
RewriteRule ^/?docs$ /slate/build/ [L]