Rewrite log says it gets applied... but it is not - apache

Im on the end with my knowledge, same for my IT admin.
We setup a new Debian GNU/Linux 8 server
Installed apache and all..
ALL works Except the darn rules. Strange thing is. The rewrite rule log says they are working but the browser from which we open the url dous not.
Here is the complete log from when i open xxx.xxx.xxx/bla
[Fri Dec 16 03:37:04.064896 2016] [rewrite:trace2] [pid 1850] mod_rewrite.c(475): [client xxx.xxx.xxx:22260] xxx.xxx.xxx - - [sccatdev.office.dig/sid#7f35b0df5d20][rid#7f35b0d3c0a0/initial] init rewrite engine with requested uri /bla/
[Fri Dec 16 03:37:04.064936 2016] [rewrite:trace3] [pid 1850] mod_rewrite.c(475): [client xxx.xxx.xxx:22260] xxx.xxx.xxx - - [sccatdev.office.dig/sid#7f35b0df5d20][rid#7f35b0d3c0a0/initial] applying pattern '^/deploy/ajax/(.+)/(\\w+)/(\\w+?)$' to uri '/bla/'
[Fri Dec 16 03:37:04.064944 2016] [rewrite:trace3] [pid 1850] mod_rewrite.c(475): [client xxx.xxx.xxx:22260] xxx.xxx.xxx - - [sccatdev.office.dig/sid#7f35b0df5d20][rid#7f35b0d3c0a0/initial] applying pattern '^/bla/$' to uri '/bla/'
[Fri Dec 16 03:37:04.064950 2016] [rewrite:trace2] [pid 1850] mod_rewrite.c(475): [client xxx.xxx.xxx:22260] xxx.xxx.xxx - - [sccatdev.office.dig/sid#7f35b0df5d20][rid#7f35b0d3c0a0/initial] rewrite '/bla/' -> '/deploy/main.phtml'
[Fri Dec 16 03:37:04.065044 2016] [rewrite:trace2] [pid 1850] mod_rewrite.c(475): [client xxx.xxx.xxx:22260] xxx.xxx.xxx - - [sccatdev.office.dig/sid#7f35b0df5d20][rid#7f35b0d3c0a0/initial] local path result: /deploy/main.phtml
[Fri Dec 16 03:37:04.065062 2016] [rewrite:trace1] [pid 1850] mod_rewrite.c(475): [client xxx.xxx.xxx:22260] xxx.xxx.xxx - - [sccatdev.office.dig/sid#7f35b0df5d20][rid#7f35b0d3c0a0/initial] go-ahead with /deploy/main.phtml [OK]
To clerify, i emptied the logs. and opend exacly 1 time the page i got a 404, but logs say it passed the main.phtml trough.. so... wtf?
For testing i made a simple bla rule:
<VirtualHost *:80>
ServerName xxxx.xxx.xxx
ServerAdmin webmaster#dig.at
DocumentRoot /data1/www/xxxx.xxx.xx/htdocs
DirectoryIndex index.html index.phtml index.php
ErrorLog /data1/www/xxxx.xxx.xx/logs/error.log
CustomLog /data1/www/xxxx.xxx.xx/logs/access.log combined
LogLevel alert rewrite:trace8
#ajax handler for
RewriteEngine On
RewriteRule ^/deploy/ajax/(.+)/(\w+)/(\w+?)$ /deploy/ajax/handler.php?path=$1&class=$2&method=$3 [L,QSA]
RewriteRule ^/bla$ /deploy/main.phtml
</VirtualHost>
yess mod rewrite ext is on... yes we traced the call in the error log... the log is given above... we tried all what google spited out.
Server is a fresh install of:
Distributor ID: Debian
Description: Debian GNU/Linux 8.6 (jessie)
Release: 8.6
Codename: jessie

Related

Is there a reason the RewriteRule [P] flag doesn't seem to work on DreamHost?

I am working on a wordpress site hosted on DreamHost. There is a page on the wordpress site that has the stub 'profile' and uses a custom template that takes a URL parameter. An example of a URL is:
http://www.example.com/profile?profileSubject=subject1
I am writing a RewriteRule in the htaccess file so that I can type a url like this:
http://www.example.com/profile/subject1
My RewriteRule in the htaccess file looks like this:
RewriteRule ^profile/([^/]*)/? http://www.example.com/profile?profileSubject=$1 [P,L]
This works insofar as typing the /profile/subject1 URL will load the content correctly, but, the URL in the address bar changes to the profile?profileSubject=subject1 URL. I believe this is what the P flag(i.e. proxy) is supposed to be for, to stop the URL in the address bar from changing.
I happen to have a copy of the site I'm working on on my local server as well, so I tried putting the exact same line in the htaccess file for my local server, and there the P flag worked, and the URL in the address bar remained /profile/subject1 when the content was loaded.
So, my conclusion is that the P flag isn't working for some reason on Dreamhost, and I'm just wondering if anyone else has had a similar issue and/or if there's anything I can do here.
EDIT: Here is the requested result of logging a rewrite attempt:
[Fri Nov 25 14:37:29.213969 2022] [rewrite:trace3] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] [perdir /Users/me/Sites/wordpress/] add path info postfix: /Users/me/Sites/wordpress/profile -> /Users/me/Sites/wordpress/profile/javonte-green
[Fri Nov 25 14:37:29.214037 2022] [rewrite:trace3] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] [perdir /Users/me/Sites/wordpress/] strip per-dir prefix: /Users/me/Sites/wordpress/profile/javonte-green -> profile/javonte-green
[Fri Nov 25 14:37:29.214042 2022] [rewrite:trace3] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] [perdir /Users/me/Sites/wordpress/] applying pattern '^/?profile/(.+)$' to uri 'profile/javonte-green'
[Fri Nov 25 14:37:29.214050 2022] [rewrite:trace2] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] [perdir /Users/me/Sites/wordpress/] rewrite 'profile/javonte-green' -> '/profile?profileSubject=javonte-green'
[Fri Nov 25 14:37:29.214056 2022] [rewrite:trace3] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] split uri=/profile?profileSubject=javonte-green -> uri=/profile, args=profileSubject=javonte-green
[Fri Nov 25 14:37:29.214062 2022] [rewrite:trace2] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] [perdir /Users/me/Sites/wordpress/] trying to replace prefix /Users/me/Sites/wordpress/ with /~me/wordpress/
[Fri Nov 25 14:37:29.214067 2022] [rewrite:trace2] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] [perdir /Users/me/Sites/wordpress/] trying to replace context docroot /Users/me/Sites with context prefix /~me
[Fri Nov 25 14:37:29.214071 2022] [rewrite:trace1] [pid 1427] mod_rewrite.c(476): [client 127.0.0.1:60404] 127.0.0.1 - - [127.0.0.1/sid#7faf94036ef8][rid#7faf948656a0/initial] [perdir /Users/me/Sites/wordpress/] internal redirect with /profile [INTERNAL REDIRECT]
EDIT 2: I finally figured it out. The solution is to refer to the profile page via wordpress's index.php rather than the 'profile' stub:
RewriteEngine On
RewriteRule ^/?profile/(.+)$ /index.php?pagename=profile&profileSubject=$1 [QSA]
Done this way, content loads correctly without changing the visible URL.
As #CBroe pointed out in the comment to the question the proxy module has to be enabled inside the http server for the P flag to be available. Though I fail to understand how the outcome you describe could occur with that rule in place. Maybe you have other, additional rules responsible for the redirection you observe?
Why do you want to use the proxy module for this? That means a full additional request each time. And it appears not necessary to me from your description.
Why don't you use a simple internal rewrite:
RewriteEngine on
RewriteRule ^/?profile/(.+)$ /profile?profileSubject=$1 [QSA,L]
That will keep the visible URL in the browser as https://www.example.com/profile/subject1 while internally calling the resource /profile?profileSubject=subject1, how ever that one is going to get resolved.

How to run wsgi and usual site on one apache server?

I have an apache server on VPS powered by centos7.
I have a usual website here, and now I want to add flask application.
httpme.tk is my flask application
mniek.ru is my website
so, the configs looks like that:
/etc/httpd/conf.d/http_error_api.conf
<VirtualHost *>
ServerName www.httpme.tk
ServerAlias httpme.tk
WSGIDaemonProcess application user=apache group=apache threads=5
WSGIScriptAlias / /var/www/http_error_api/wsgi.py
WSGIScriptReloading On
<Directory /var/www/http_error_api>
WSGIProcessGroup application
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
/etc/httpd/conf.d/mniek.ru.conf
<VirtualHost *:80>
ServerAdmin n-i-k-i-t#yandex.ru
ServerName mniek.ru
ServerAlias www.mniek.ru
DocumentRoot /var/www/mniek.ru
<Directory /var/www/mniek.ru>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/www/mniek.ru/logs/error.log
CustomLog /var/www/mniek.ru/logs/access.log common
</VirtualHost>
<VirtualHost *:443>
ServerAdmin n-i-k-i-t#yandex.ru
ServerName mniek.ru
ServerAlias www.mniek.ru
DocumentRoot /var/www/mniek.ru
<Directory /var/www/mniek.ru>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/www/mniek.ru/logs/error.log
CustomLog /var/www/mniek.ru/logs/access.log common
</VirtualHost>
And my /var/www/http_error_api/wsgi.py file:
from sys import path
path.insert(0, '/var/www/http_error_api')
from main import app as application
Apache logs:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 0.0.26.144. Set the 'ServerName' directive globally to suppress this message
[Sun Jul 19 07:50:35.700799 2020] [lbmethod_heartbeat:notice] [pid 65294] AH02282: No slotmem from mod_heartmonitor
[Sun Jul 19 07:50:35.725938 2020] [mpm_prefork:notice] [pid 65294] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16 mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Sun Jul 19 07:50:35.725986 2020] [core:notice] [pid 65294] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Sun Jul 19 07:55:41.639120 2020] [mpm_prefork:notice] [pid 65294] AH00170: caught SIGWINCH, shutting down gracefully
[Sun Jul 19 07:55:42.784997 2020] [suexec:notice] [pid 65403] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 0.0.26.144. Set the 'ServerName' directive globally to suppress this message
[Sun Jul 19 07:55:42.838510 2020] [lbmethod_heartbeat:notice] [pid 65403] AH02282: No slotmem from mod_heartmonitor
[Sun Jul 19 07:55:42.868170 2020] [mpm_prefork:notice] [pid 65403] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16 mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Sun Jul 19 07:55:42.868215 2020] [core:notice] [pid 65403] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Sun Jul 19 08:06:12.281355 2020] [mpm_prefork:notice] [pid 65403] AH00170: caught SIGWINCH, shutting down gracefully
[Sun Jul 19 08:06:13.880590 2020] [suexec:notice] [pid 65576] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 0.0.26.144. Set the 'ServerName' directive globally to suppress this message
[Sun Jul 19 08:06:13.935885 2020] [lbmethod_heartbeat:notice] [pid 65576] AH02282: No slotmem from mod_heartmonitor
[Sun Jul 19 08:06:13.973518 2020] [mpm_prefork:notice] [pid 65576] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16 mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Sun Jul 19 08:06:13.973573 2020] [core:notice] [pid 65576] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
The problem is: when I open mniek.ru, I'm getting to my website. Also, when I go to httpme.tk, I'm also getting to my website, not to my flask application. What's wrong?

.htaccess Debug Require expr

I'm trying to allow all requests to a specific url for webhooks to a development platform. Require expr works partially.
This website should only be completly accessible for specifig users. Using
"Require expr %{REQUEST_URI} =~ m#^.*webhook.*$#" I'm trying to get this working. I also tried LocationMatch, which won't work for other circumstances.
AuthType Basic
AuthName "Please enter password"
require group xy yz
<IfModule mod_authz_core.c>
<RequireAny>
Require expr %{REQUEST_URI} =~ m#^.*webhook.*$#
...
</RequireAny>
</IfModule>
If I call the url example.com/webhook/xyz/ the request is not accepted and returns the realm login.
The log:
[Mon May 27 20:15:58.972495 2019] [authz_core:debug] [pid 15344] mod_authz_core.c(820): [client xxx.xxx.xxx.xxx:50341] AH01626: authorization result of Require group xy yz: denied (no authenticated user yet)
[Mon May 27 20:15:58.972519 2019] [authz_core:debug] [pid 15344] mod_authz_core.c(820): [client xxx.xxx.xxx.xxx:50341] AH01626: authorization result of Require expr %{REQUEST_URI} =~ m#^.*webhook.*$#: granted
[Mon May 27 20:15:58.972526 2019] [authz_core:debug] [pid 15344] mod_authz_core.c(820): [client xxx.xxx.xxx.xxx:50341] AH01626: authorization result of <RequireAny>: granted
[Mon May 27 20:15:58.972813 2019] [authz_core:debug] [pid 15344] mod_authz_core.c(820): [client xxx.xxx.xxx.xxx:50341] AH01626: authorization result of Require group xy yz: denied (no authenticated user yet)
[Mon May 27 20:15:58.972824 2019] [authz_core:debug] [pid 15344] mod_authz_core.c(820): [client xxx.xxx.xxx.xxx:50341] AH01626: authorization result of Require expr %{REQUEST_URI} =~ m#^.*webhook.*$#: denied
[Mon May 27 20:15:58.973126 2019] [authz_core:debug] [pid 15344] mod_authz_core.c(820): [client xxx.xxx.xxx.xxx:50341] AH01626: authorization result of <RequireAny>: denied (no authenticated user yet)
[Mon May 27 20:15:58.973154 2019] [auth_basic:error] [pid 15344] [client xxx.xxx.xxx.xxx.47:50341] AH01614: client used wrong authentication scheme: /router.php
And I really don't know why he is denying this requests after it was granted. Maybe a redirect? PHP says $_SERVER['REQUEST_URI'] is still the same after I tried to grant my ip address. So I guess it's not a redirect issue. Any idea what can cause that problem or how to debug this?

cant get virtual host to work in wamp

Version:2.5
I know there are many guides to do this but it does not work for some reason and I can't even this is what I did
in Virtual Host
<VirtualHost *:80>
DocumentRoot "D:/wamp/www"
ServerName localhost
<Directory "D:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/elgg"
ServerName elgg.local
ServerAlias elgg.local
<Directory "C:/elgg">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
in Hosts File
127.0.0.1 localhost
::1 localhost
127.0.0.1 elgg.local
::1 elgg.local
in Conf File
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
I did all this but when i type elgg.local it searches for an actual website
last 10 apache lines
[Fri Oct 16 10:33:49.873625 2015] [mpm_winnt:notice] [pid 1576:tid 668] AH00418: Parent: Created child process 1252
[Fri Oct 16 10:33:50.405080 2015] [mpm_winnt:notice] [pid 1252:tid 600] AH00354: Child: Starting 64 worker threads.
[Fri Oct 16 12:09:50.487027 2015] [mpm_winnt:notice] [pid 1576:tid 668] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Fri Oct 16 12:09:52.490354 2015] [mpm_winnt:notice] [pid 1252:tid 600] AH00364: Child: All worker threads have exited.
[Fri Oct 16 12:09:52.606432 2015] [mpm_winnt:notice] [pid 1576:tid 668] AH00430: Parent: Child process 1252 exited successfully.
[Fri Oct 16 12:09:54.598384 2015] [mpm_winnt:notice] [pid 6408:tid 656] AH00455: Apache/2.4.9 (Win64) PHP/5.5.12 configured -- resuming normal operations
[Fri Oct 16 12:09:54.598384 2015] [mpm_winnt:notice] [pid 6408:tid 656] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:42:59
[Fri Oct 16 12:09:54.598384 2015] [core:notice] [pid 6408:tid 656] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d C:/wamp/bin/apache/apache2.4.9'
[Fri Oct 16 12:09:54.600385 2015] [mpm_winnt:notice] [pid 6408:tid 656] AH00418: Parent: Created child process 8152
[Fri Oct 16 12:09:54.943610 2015] [mpm_winnt:notice] [pid 8152:tid 580] AH00354: Child: Starting 64 worker threads.
Turns out there was not much, if anything, wrong with the Apache config.
However #Tryhard was using the Google Chrome browser, and that was doing a google search whenever the URL elgg.local was entered and not using it as a domainname. IE did not make this mistake, so it must be a Chrome issue!
The popular solution, that I have used before, of
Enter chrome://flags in the address bar and set "Built-in Asynchronous DNS" to "Disabled", then restart the browser. No longer seems to work as that option is no longer available in the flags parameters.
Dont know if this is a Chrome bug or just an oddity, but the only solution we could come up with was to add a trailing / to the domain name. That made Chrome use the url rather than start a search!
So elgg.local did a search
and elgg.local/ ran the website code.
If you ever get odd unexpected behaviours while using Chrome, always try FF and/or IE before anything else, to make sure the same things happen as Chrome seems to have quite a few odd behaviours when dealing with local development websites.

XAMPP for Windows - Apache not starting

I was trying to set up multiple websites on my computer, following this tutorial: https://delanomaloney.com/2013/07/how-to-set-up-virtual-hosts-using-xampp/
I stopped apache and then changed two files: hosts and httpd-vhosts.conf.
Here is hosts:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 www.sewing.dev
And httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/sewing"
ServerName sewing.dev
ServerAlias www.sewing.dev
<Directory "c:/xampp/htdocs/sewing">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
I saved the files and clicked to restart apache. Nothing happens. It says that it's attempting to start but doesn't actually start. I checked the error logs, but didn't see anything that I could understand.
Error log:
[Fri May 22 21:33:45.065111 2015] [ssl:warn] [pid 2136:tid 384] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri May 22 21:33:46.063513 2015] [ssl:warn] [pid 2136:tid 384] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri May 22 21:33:55.657529 2015] [mpm_winnt:notice] [pid 2136:tid 384] AH00455: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15 configured -- resuming normal operations
[Fri May 22 21:33:55.657529 2015] [mpm_winnt:notice] [pid 2136:tid 384] AH00456: Apache Lounge VC11 Server built: Jul 17 2014 11:50:08
[Fri May 22 21:33:55.657529 2015] [core:notice] [pid 2136:tid 384] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Fri May 22 21:33:55.657529 2015] [mpm_winnt:notice] [pid 2136:tid 384] AH00418: Parent: Created child process 3600
[Fri May 22 21:33:57.654333 2015] [ssl:warn] [pid 3600:tid 276] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri May 22 21:33:58.044334 2015] [ssl:warn] [pid 3600:tid 276] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri May 22 21:33:58.106734 2015] [mpm_winnt:notice] [pid 3600:tid 276] AH00354: Child: Starting 150 worker threads.
[Fri May 22 21:41:40.093670 2015] [mpm_winnt:notice] [pid 2136:tid 384] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Fri May 22 21:41:42.121674 2015] [mpm_winnt:notice] [pid 3600:tid 276] AH00364: Child: All worker threads have exited.
[Fri May 22 21:41:42.449274 2015] [mpm_winnt:notice] [pid 2136:tid 384] AH00430: Parent: Child process 3600 exited successfully.
When I comment out all of the httpd-vhosts.conf file, apache will start.
You need to close your default virtual host directive.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost> # <<< missing closing directiv!!!