I have one application that listens on TCP I want to accomplish the following redirection:

www.example.com/?requestid=123456 -->

My understanding is that if I will not rewrite something explicitly, it will follow the regular path to the /var/www/html.

My /etc/apache2/sites-enabled/000-default.conf configuration:

<VirtualHost *:80>
        ServerName example.com
        ServerAdmin example@example.com
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Location />
        RewriteEngine On
        RewriteRule ^/?requestid(.*)$$1 [P]
        Order allow,deny
        Allow from all


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Why it does not rewrite properly and keep hitting the normal patch?

Not Found
The requested URL /bullshit was not found on this server.

Apache/2.4.25 (Debian) Server at example.com Port 80

Answer was posted on: [stack overflow]

From RewriteRule Directive:

In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html"). This is the (%-decoded) URL-path.

If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.

So, you will need something like this:

RewriteEngine On
RewriteCond %{QUERY_STRING} requestid=(.+)
RewriteRule ^/$ [P]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.