just_user
just_user

Reputation: 12059

htaccess redirection enters redirection loop

I've created a backend using modx which is on a server with the following url:

http://www.server.com/company-name/en/pages/

The live version of the site has a domain that points to the /en/ directory. so for correct access I have to go to:

http://www.domain.com/en/pages/

But modx still adds the folder "company-name" to everything. Which then points to a page that doesn't exist.

When I make the following in .htaccess the page enters into a redirection loop and errors.

RewriteEngine On
RewriteBase /de/pages/
RewriteCond %{HTTP_HOST} .

RewriteCond %{HTTP_HOST} !^domain\.com/company-name/en/pages/ [NC]
RewriteRule (.*) http://www\.domain\.ch/en/pages/$1 [R=301,L]

How can I make this work correctly? So that the directory "company-name" is never part of the url?

Upvotes: 1

Views: 103

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

Your %{HTTP_HOST} will never look like domain\.com/company-name/en/pages/, since the Host field contains no path information, just a hostname. So you want:

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^company-name/(.*)$ http://www.domain.com/en/pages/$1 [L,R=301]

You'll need to put the htaccess file and those rules in the document root of your www.server.com site.

Upvotes: 2

Related Questions