1

I'm setting up a new Linux server. I'd like to silently redirect

www.domain.com/whatever to www.domain.com/flows/default/whatever

unless the flow is explicitly specified, such as

www.domain.com/flows/beta/whatever

Inside the VirtualHost entry for my domain, I have the following:

LogLevel error rewrite:trace6

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,NC,R=301]

    RewriteCond %{REQUEST_URI} !^/flows/ [NC]
    RewriteRule ^ /flows/default%{REQUEST_URI} [NC]

</IfModule>

Where "domain.com" is my actual domain obv.

These are the same two rules that I've always used in the past, however something is not working now. Any URL which is modified by the second rule brings up a 404 page with a message like the following:

The requested URL /cgi-sys/ea-php70/index.php was not found on this server.

Halfway through the output log, is the following line:

init rewrite engine with requested uri /cgi-sys/ea-php70/index.php

I don't know enough about the way everything works to understand why CGI/PHP is being involved in the procedure at all. Here's the full log:

[domain.com/sid#6de4c962d30][rid#70829c002970/initial] init rewrite engine with requested uri /index.php
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] applying pattern '^' to uri '/index.php'
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] RewriteCond: input='domain.com' pattern='^domain.com$' [NC] => matched
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] rewrite '/index.php' -> 'http://www.domain.com/index.php'
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] explicitly forcing redirect with http://www.domain.com/index.php
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] escaping http://www.domain.com/index.php for redirect
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] redirect to http://www.domain.com/index.php [REDIRECT/301]
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] init rewrite engine with requested uri /index.php
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] applying pattern '^' to uri '/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] RewriteCond: input='www.domain.com' pattern='^domain.com$' [NC] => not-matched
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] applying pattern '^' to uri '/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] RewriteCond: input='/index.php' pattern='!^/flows/' [NC] => matched
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] rewrite '/index.php' -> '/flows/default/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] local path result: /flows/default/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] prefixed with document_root to /home/mario/public_html/flows/default/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] go-ahead with /home/mario/public_html/flows/default/index.php [OK]
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] init rewrite engine with requested uri /cgi-sys/ea-php70/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] applying pattern '^' to uri '/cgi-sys/ea-php70/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] RewriteCond: input='www.domain.com' pattern='^domain.com$' [NC] => not-matched
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] applying pattern '^' to uri '/cgi-sys/ea-php70/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] RewriteCond: input='/cgi-sys/ea-php70/index.php' pattern='!^/flows/' [NC] => matched
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] rewrite '/cgi-sys/ea-php70/index.php' -> '/flows/default/cgi-sys/ea-php70/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] local path result: /flows/default/cgi-sys/ea-php70/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] prefixed with document_root to /home/mario/public_html/flows/default/cgi-sys/ea-php70/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] go-ahead with /home/mario/public_html/flows/default/cgi-sys/ea-php70/index.php [OK]
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] init rewrite engine with requested uri /404.shtml
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] applying pattern '^' to uri '/404.shtml'
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] RewriteCond: input='www.domain.com' pattern='^domain.com$' [NC] => not-matched
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] applying pattern '^' to uri '/404.shtml'
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] RewriteCond: input='/404.shtml' pattern='!^/flows/' [NC] => matched
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] rewrite '/404.shtml' -> '/flows/default/404.shtml'
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] local path result: /flows/default/404.shtml
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] prefixed with document_root to /home/mario/public_html/flows/default/404.shtml
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] go-ahead with /home/mario/public_html/flows/default/404.shtml [OK]

So the official question is, why is my redirect not working and what do I need to do to correct it?

Let me know if you need any other info. Thanks guys.

UPDATE

Configuration is CentOS, cPanel, Apache 2.4, MPM Event, PHP-FPM, PHP 7, suEXEC.

Ok, so I've added RewriteCond %{REQUEST_URI} !^/cgi-sys/ [NC] to the second rule just to get it to work, and it does now. I'd still like to know what's going on internally just for personal knowledge if anyone has an idea.

DaiBu
  • 113
  • From the log it does seem to be "working", but then another rewrite is triggered for /cgi-sys/ea-php70/index.php that is breaking. Can you add the rest of your config to question? Do you have any .htaccess files? You might just need to add some exceptions? It seems you don't have an exception for your defined ErrorDocument, so this is also being rewritten (you may not have had a custom ErrorDocument defined in the past?). What version of Apache? – MrWhite Jan 20 '17 at 10:03
  • @w3dk - I added my server config to the OP. Also added a condition to bypass the weirdness (see update). Is that what you meant by an exception? ErrorDocuments were defined, just not created. And I want the error doc locations redirected also, so each flow can have its own control over the look of them. I'm not worried about that part. I added a 404.shtml file just to cover all bases and the problem still persists without the !^/cgi-sys/ condition I added as a workaround. – DaiBu Jan 20 '17 at 10:55
  • @w3dk - In what other ways does mod_rewrite get triggered other than just for changing URLs? Looking at the log, even when there are no errors, it still goes through the routine with /cgi-sys/ea-php70. It seems like PHP's location should have nothing to do with it. – DaiBu Jan 20 '17 at 11:07
  • Yes, that's the sort of thing I meant by an exception. However, I'm not sure where your /cgi-sys/ea-php70 request is coming from - something to do with the way EasyApache/suEXEC(?) is configured to handle the PHP request - although I would not expect to see this? Is PHP70 native? mod_rewrite gets "triggered" for any request or subrequest. It isn't only used for "changing URLs", although URL rewriting is it's primary use. – MrWhite Jan 20 '17 at 11:19
  • @w3dk - Yes, PHP70 was installed via EasyApache4 as part of cPanel's MultiPHP system. I think it lets you choose different PHP versions for different virtual hosts, maybe other determining factors also. Maybe the extra request is due to some kind of MultiPHP routing to the correct PHP version? Or something? I dunno. Lol. I'm just surprised I'm the only one who's ever ran into this. This is a pretty common type of redirect, no? My internet searches didn't really find anything related. – DaiBu Jan 21 '17 at 12:00

0 Answers0