Search code examples
apache.htaccessmod-rewritehttp-redirectmodx

htaccess subdomain redirect in infinite loop


I have a domain and also a subdomain which points via dns to the domain.

We want request at subdomain.domain.com to point to /a/b/page while keeping the subdomain.

eg: subdomain.domain.com goes to subdomain.domain.com/a/b/page

It currently is in an infinite loop.

RewriteCond %{HTTP_HOST} subdomain.mydomain.com
RewriteCond %{REQUEST_URI} !^/a/b/page$
RewriteRule (.*) http://subdomain.mydomain.com/a/b/page [R=301,L]

We are using apache2 and modx as the cms.


Solution

  • According to your example:

    subdomain.domain.com

    goes to (Redirects to, is rewritten as)

    subdomain.domain.com/a/b/page

    RewriteCond %{HTTP_HOST} ^subdomain.*$
    RewriteRule (.*) http://subdomain.mydomain.com/a/b/page [R=301,L]
    

    There is no need to check the URI as there is NONE.