Forum Moderators: phranque

Message Too Old, No Replies

htaccess: from subdirectories to subdomains

         

MoserWebPublishing

11:44 am on Apr 6, 2010 (gmt 0)

10+ Year Member



I have a wordpress installation which was installed in subdirectories and I would like to change it to subdomains.

Old structure:
(de) example.com/
(en) example.com/en/
(fr) example.com/fr/

New structure:
(de) de.example.com/
(en) en.example.com/
(fr) fr.example.com/

My htaccess so far:

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^en/(.+) http://en.example.com/$1 [R=301,L,NC]
RewriteRule ^fr/(.+) http://fr.example.com/$1 [R=301,L,NC]
RewriteRule ^(.+) http://de.example.com/$1 [R=301,L,NC]


It's not working I'm getting the error message that redirects will never end.

Andreas

phranque

2:09 pm on Apr 6, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], MoserWebPublishing!

a RewriteCond (or set of RewriteConds) only applies to the following RewriteRule.

maybe this will work better:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^en/(.+) http://en.example.com/$1 [R=301,L,NC]

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^fr/(.+) http://fr.example.com/$1 [R=301,L,NC]

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.+) http://de.example.com/$1 [R=301,L,NC]

MoserWebPublishing

2:56 pm on Apr 6, 2010 (gmt 0)

10+ Year Member



Thanks - everything works now.

I just had to change the last Rule, as there are the Wordpress-admin files under example.com which shouldn't be redirected.

So I changed it to:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(files|tag|category|2008|2009|2010)/(.+) [de.example.com...] [R=301,L,NC]

So if anybody else is running in the same problem ;)
Andreas

jdMorgan

3:19 pm on Apr 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In order to prevent that "list" from growing over time and becoming a performance and maintenance headache, consider using a negative-match RewriteCond to exclude /wp-admin requests instead. With your original rule:

RewriteCond $1 !^wp-admin/

The "wp-admin" shown here is just an example. Adjust it to suit the actual path on your site.

Also note that [NC] is not needed if your pattern doesn't contain literal letters or alphabetic character-groups such as "[a-z]" or "[A-Z]".

Jim