Note that there are some explanatory texts on larger screens.

plurals
  1. POhtaccess rewrite - prevent multiple redirects
    primarykey
    data
    text
    <p>The following regex works perfectly except for under the condition when the user goes to <code>examplesite1.com/site1</code>. When this happens the page fails because of multiple redirects in which it continues to add the <code>request=site1</code> query to the URL. I thought that adding <code>RewriteCond %{ENV:REDIRECT_STATUS} ^$</code> would fix this issue however that seemed to not be the case. </p> <p>This setup is for a multi-domain website. There are three folders site1, site2, and shared. There are also rewrite rules for site2 and shared that are not shown as they do not effect this issue.</p> <pre><code># if the resource exists in site1 return it to the user RewriteCond %{HTTP_HOST} examplesite1.com$ RewriteCond %{DOCUMENT_ROOT}/site1/%{REQUEST_URI} -f RewriteRule ^(.*)$ /site1/$1 [QSA,L] # no file found, send URI to CMS RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php?request=$1 [QSA,L] </code></pre> <p>complete .htaccess file:</p> <pre><code>AddDefaultCharset UTF-8 # Disallow browsing file directories Options -Indexes RewriteEngine on RewriteBase / #remove the trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} (.*)/$ RewriteRule ^(.+)/$ /$1 [R=301,L] RewriteCond %{HTTP_HOST} examplesite1.com$ RewriteCond %{DOCUMENT_ROOT}/site1/%{REQUEST_URI} -f RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.*)$ /site1/$1 [QSA,L] RewriteCond %{HTTP_HOST} examplesite2.com$ RewriteCond %{DOCUMENT_ROOT}/site2/%{REQUEST_URI} -f RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.*)$ /site2/$1 [QSA,L] RewriteCond %{DOCUMENT_ROOT}/shared/%{REQUEST_URI} -f RewriteRule ^(.*)$ /shared/$1 [QSA,L] # resources not to be public are sent to CMS RewriteCond %{REQUEST_FILENAME} (\.inc\.|\.tpl$) RewriteRule ^(.*)$ /index.php?request=$1 [QSA,L] # no resource found, send URI to CMS RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.*)$ /index.php?request=$1 [QSA,L] </code></pre>
    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.
    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