Note that there are some explanatory texts on larger screens.

plurals
  1. POmass virtual hosting and rewrite rules causing recursive internal redirect
    primarykey
    data
    text
    <p>I'm using vhost_alias for to do <a href="http://httpd.apache.org/docs/2.2/vhosts/mass.html" rel="nofollow">mass virtual hosting</a> and have several sites using mod_rewrite to manage their front controllers.</p> <p>I don't think this is a specific symfony issue, but I'm using symfony.</p> <p>Now most requests that match any rewrite rule end up in an infnite redirect loop that causes an http error 500.</p> <p>I checked the log files and this is what I found:</p> <pre><code>(3) [perdir /home/user/www/mysite/] strip per-dir prefix: /home/user/www/mysite/app_dev.php -&gt; app_dev.php (3) [perdir /home/user/www/mysite/] applying pattern '^$' to uri 'app_dev.php' (3) [perdir /home/user/www/mysite/] strip per-dir prefix: /home/user/www/mysite/app_dev.php -&gt; app_dev.php (3) [perdir /home/user/www/mysite/] applying pattern '^(.*)$' to uri 'app_dev.php' (2) [perdir /home/user/www/mysite/] rewrite 'app_dev.php' -&gt; 'web/app_dev.php' (3) [perdir /home/user/www/mysite/] add per-dir prefix: web/app_dev.php -&gt; /home/user/www/mysite/web/app_dev.php (1) [perdir /home/user/www/mysite/] internal redirect with /home/user/www/mysite/web/app_dev.php [INTERNAL REDIRECT] (3) [perdir /home/user/www/mysite/] add path info postfix: /home/user/www/mysite/home -&gt; /home/user/www/mysite/home/user/www/mysite/web/app_dev.php (3) [perdir /home/user/www/mysite/] strip per-dir prefix: /home/user/www/mysite/home/user/www/mysite/web/app_dev.php -&gt; home/user/www/mysite/web/app_dev.php (3) [perdir /home/user/www/mysite/] applying pattern '^$' to uri 'home/user/www/mysite/web/app_dev.php' </code></pre> <p>As you can see, after the internal redirect line, the absolute path becomes part of the URI being matched, this uri of course does not match any files and is processed again as a completely new uri, this results in a new absolute path appended at the URI. This process repeats itself until reaching the configured limit.</p> <p>I tried this without the virtual hosts configuration (which works fine) and noticed that before the internal redirect there is a new line:</p> <pre><code>(2) [perdir /home/user/www/mysite/] strip document_root prefix: /home/user/www/mysite/web/app_dev.php -&gt; /web/app_dev.php (1) [perdir /home/user/www/mysite/] internal redirect with /web/app_dev.php [INTERNAL REDIRECT] </code></pre> <p>After this redirect the actual file is matched and there is no problem.</p> <p>Shouldn't the virtual document_root be stripped in the virtual configuration as well as in the regular configuration?</p> <p>I don't understand why the virtual document root is considered part of the url in the internal redirect. This seems to be plain wrong.</p> <p>Am I missing some configuration option?</p> <p>Here is my .htaccess file:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteRule ^$ web/ [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ web/$1 [QSA,L] &lt;/IfModule&gt; </code></pre> <p>Here is my apache config file:</p> <pre><code># get the server name from the Host: header UseCanonicalName Off &lt;VirtualHost *:80&gt; LogLevel debug RewriteLogLevel 3 RewriteLog "/var/log/apache2/rewrite.log" VirtualDocumentRoot /home/user/www/%1 #DocumentRoot /home/user/www #RewriteEngine on #RewriteCond %{HTTP_HOST} ^(.*)\.dev$ [NC] #RewriteRule ^/(.+)$ /home/user/www/%1/$1 [QSA,L] &lt;Directory /&gt; Options FollowSymLinks AllowOverride None &lt;/Directory&gt; &lt;Directory /home/user/www&gt; Options Indexes FollowSymLinks -MultiViews AllowOverride All Order allow,deny allow from all &lt;/Directory&gt; ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ &lt;Directory "/usr/lib/cgi-bin"&gt; AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all &lt;/Directory&gt; ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined &lt;/VirtualHost&gt; </code></pre> <p>Below the VirtualDocumentRoot declaration there are some commented out rewrite rules.</p> <p>That was an attempt at replacing the VirtualDocumentRoot with rewrite rules, but it had a similar problem: the document_root being striped was /home/user/www, leaving the hostname as part of the url, so I end up having the same recursive problem.</p> <p>So I would like to know if someone has ever made mod_vhost_alias work with mod_rewrite. I really tried to search everywhere (even google!) but could not find much information about this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload