Category Archives: apache2

redirect subdirectory http and https to new domain

I know it sounds like this is a question that has been asked before, but my exact situation hasn't been covered and I've been unable to find a solution.

My situation:

I have one server running Apache2, with two domains pointing to in domain registrar DNS. Lets call the domains foo.com and bar.com.

I had and old site in a subdirectory /bar, but I got the domain bar.com to use for this site instead. I've already managed to get (with the use of Virtual Hosts) http://bar.com to redirect to https://bar.com and display the site in the /bar subdirectory.

The redirect from http://bar.com to https://bar.com is handled by .htaccess in the bar.com DocumentRoot (which is the /bar subdirectory).

But I have links on Facebook and Twitter (and possible elsewhere due to sharing) that point to http://foo.com/bar/various_pages and https://foo.com/bar/various_pages.

I have managed to get http://foo.com/bar/various_pages to redirect to https://bar.com/various_pages using the following in .htaccess of foo.com DocumentRoot:

RewriteBase /roadkingvtc
RewriteRule (.*)  http://roadkingvtc.com/$1 [R,L]

However https://foo.com/bar/various_pages redirects to https://bar.com and instead of https://bar.com/various_pages.

So my question is how can I get both http://foo.com/bar/various_pages and https://foo.com/bar/various_pages to redirect to http://bar.com/various_pages? Without breaking what's working now. Thanks for reading.

redirect subdirectory http and https to new domain

I know it sounds like this is a question that has been asked before, but my exact situation hasn't been covered and I've been unable to find a solution.

My situation:

I have one server running Apache2, with two domains pointing to in domain registrar DNS. Lets call the domains foo.com and bar.com.

I had and old site in a subdirectory /bar, but I got the domain bar.com to use for this site instead. I've already managed to get (with the use of Virtual Hosts) http://bar.com to redirect to https://bar.com and display the site in the /bar subdirectory.

The redirect from http://bar.com to https://bar.com is handled by .htaccess in the bar.com DocumentRoot (which is the /bar subdirectory).

But I have links on Facebook and Twitter (and possible elsewhere due to sharing) that point to http://foo.com/bar/various_pages and https://foo.com/bar/various_pages.

I have managed to get http://foo.com/bar/various_pages to redirect to https://bar.com/various_pages using the following in .htaccess of foo.com DocumentRoot:

RewriteBase /roadkingvtc
RewriteRule (.*)  http://roadkingvtc.com/$1 [R,L]

However https://foo.com/bar/various_pages redirects to https://bar.com and instead of https://bar.com/various_pages.

So my question is how can I get both http://foo.com/bar/various_pages and https://foo.com/bar/various_pages to redirect to http://bar.com/various_pages? Without breaking what's working now. Thanks for reading.

How to have basic authentication for inner folders too?

I want to have a simple username/password basic authentication for my website, located under /var/www/html/mySite

So, after defining my user and pass in the .htpasswd, I did the following to my host configuration:

<Directory "/var/www/html">
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /var/www/.htpasswd
    Require valid-user admin user

It works fine as long the file I'm trying to access is under /mySite, anyway my ajax call fail when I try accessing a file which is under /mySite/myAssets. I think it could be because the above configuration stops at the root level...how to make is recursive?

Edit:

In the response header I get:

WWW-Authenticate: Basic realm="Restricted Content"

How to have basic authentication for inner folders too?

I want to have a simple username/password basic authentication for my website, located under /var/www/html/mySite

So, after defining my user and pass in the .htpasswd, I did the following to my host configuration:

<Directory "/var/www/html">
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /var/www/.htpasswd
    Require valid-user admin user

It works fine as long the file I'm trying to access is under /mySite, anyway my ajax call fail when I try accessing a file which is under /mySite/myAssets. I think it could be because the above configuration stops at the root level...how to make is recursive?

Edit:

In the response header I get:

WWW-Authenticate: Basic realm="Restricted Content"

Apache2 blacklist ips pragmatically

My client has a server that is constantly being attacked (DDOS) by random ips from random countries, we simply see many requests to server from the same ip, something like 500 requests a second,

we have tried to install mod_evasive and it did not work...

How can i defend against these attacks? (i know that a code solution wont be best, but it is an option if possible)

apache2 DirectoryIndex change does not bypass cached index

I am trying to make sure that visitors to my website see the latest version. To this end I have written a script to rename appropriate files and requests so that they append a fresh version number at build time. This includes the index file, let's call it index-v123.html.

I have uploaded this built source and pointed my apache2 server to the new index file by including

DirectoryIndex index-v123.html

in my apache2.conf. I have restarted it, and when viewing the website in chrome incognito mode or on hard refresh I can see that all the new files are loaded and the website works as expected.

My issue is that in my normal browser, when I visit the URL, I still load up a cached version of index.html. Clearly changing the DirectoryIndex didn't convince the client to go to the new index file like I'd hoped...

So can I do anything to make this happen?

(Also may be relevant: I am running a progressive web app using Polymer 2.0, with a service-worker.js that is built automatically by polymer build.)

Apache + mod_wsgi + flask app: "Unable to get bucket brigade for request" error in logs

I have a apache2/mod_wsgi/flask/python2.7 app. Sometimes such line appears in log file:

Partial results are valid but processing is incomplete: [client 45.132.96.124:34500] mod_wsgi (pid=13920): Unable to get bucket brigade for request., referer: https://my-site.com/some_url/

What is "bucket brigade" and what this error actually means? Is it apache error or wsgi server error? What does lead to this error? If this is some unhandled exception - how to handle it and where?

Thanks in advance.

codiad in subdir results in error 500

i've installed codiad in a subdir of a webserver (xyz.com/codiad). the root dir .htaccess file is as follows:

Options -Indexes
AddDefaultCharset utf-8
AddCharset utf-8 .js
AddCharset utf-8 .php
AddCharset utf-8 .md
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule (.+)\.htm$ index.php
RewriteRule (.+)\.md$ index.php
RewriteRule (.+)\.txt$ index.php
ErrorDocument 404 /404.htm

trying to do the inital setup of codiad results in an internal server error 500 of the process

.../codid/components/install/process.php

and i assume codiad needs its own .htaccess file ..

i have to say that i have no access to the apache config files, only FTP to the webspace

generally, how can i override the .htaccess file of any parent directory ?

Trying to rewrite a local url to another

I want to be able to do the following:

ReWrite /test -> /test.php

Also:

ReWrite /Test/test -> /Test/test.php

I want to be able to do this only for those mentioned urls. Also, I do not want direct access to .php urls. For example, if the user navigates to /Test/bla.php or any other links, he would be automatically be directed to the /index. The main reason I am doing this is that I do not want the user to know I am using .php. Here is what I tried:

RewriteEngine On
RewriteRule ^Test/test$ /Test/test.php
RewriteRule ^test$ test.php
ErrorDocument 404 /index.php

This works to some extent. I can navigate to /Test/test and it redirects me to /Test/test.php without issues. Though, if I do something like /test (from the root), I see the Test folder instead. Also, 404 does not work in this .htaccess above. I can navigate to any missing url and it complains that it is not there.

I am new to web hosting. So, I am kind of confused by the .htaccess.

Thanks for your time.

DateTimeZone Error Apache2 Log

when I try to enter the site a white page appears. anyway I checked all files and everything look good. also , my server has a time zone. I don't know What Should I do ?

[Mon May 21 21:06:21.190385 2018] [:error] [pid 13340] [client 89.64.24.10:19041] PHP Notice:  Undefined property: object::$default_timezone in /var/www/html/frontend/lib/common.php on line 92
[Mon May 21 21:06:21.193439 2018] [:error] [pid 13340] [client 89.64.24.10:19041] PHP Notice:  date_default_timezone_set(): Timezone ID '' is invalid in /var/www/html/frontend/lib/common.php on line 92
[Mon May 21 21:06:21.193476 2018] [:error] [pid 13340] [client 89.64.24.10:19041] PHP Notice:  Undefined property: object::$default_timezone in /var/www/html/frontend/lib/common.php on line 93
[Mon May 21 21:06:21.193603 2018] [:error] [pid 13340] [client 89.64.24.10:19041] PHP Fatal error:  Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone () in /var/www/html/frontend/lib/common.php:93\nStack trace:\n#0 /var/www/html/frontend/lib/common.php(93): DateTimeZone->__construct('')\n#1 /var/www/html/frontend/htdocs/index.php(4): include('/var/www/html/f...')\n#2 {main}\n  thrown in /var/www/html/frontend/lib/common.php on line 93

time zone line 92-93-94-95 (common.php)

date_default_timezone_set($CFG->default_timezone);
$dtz = new DateTimeZone($CFG->default_timezone);
$dtz1 = new DateTime('now', $dtz);
$CFG->timezone_offset = $dtz->getOffset($dtz1);