1

I have a site that I'm manually translating. The normal version is in English and the translated version is in Spanish.

The translated version is accessible through http://example.com/file.php?language=es (es for espanol) I want the URL after the domain to be unaltered by the change in translation, so I'm trying to use http://es.example.com/ instead.

This is the current state of my htaccess:

RewriteCond %{HTTP_HOST} !^example\.site$
RewriteRule home/$ /index.php [L,QSA]
RewriteRule contact-us/$ /contact-us.php [L,QSA]
RewriteRule our-location/$ /our-location.php [L,QSA]
RewriteRule gallery/$ /gallery.php [L,QSA]
RewriteRule (.*)/$ /user.php?display_name=$1 [L,QSA]

RewriteCond %{HTTP_HOST} !^es\.example\.site$
RewriteRule home/$ /index.php?language=es [L,QSA]
RewriteRule contact-us/$ /contact-us.php?language=es [L,QSA]
RewriteRule our-location/$ /our-location.php?language=es [L,QSA]
RewriteRule gallery/$ /gallery.php?language=es [L,QSA]
RewriteRule (.*)/$ /user.php?language=es&display_name=$1 [L,QSA]

The first set of rules under !^example.site$ all override the rules from under !^es.example.site$, so when I access the pages with or without the "es" subdomain, I'm getting the English version either way. If I place the subdomain rules (and rewrite condition) above the non-subdomain rules then the same thing happens except the site is only translated in Spanish.

Any help would be greatly appreciated.

EDIT:

The fixed rules, thanks to the help of @hjpotter92

RewriteRule ^home/?$ /index.php [NC,QSA,S=3]
RewriteRule ^(contact-us|our-location|gallery)/?$ /$1.php [NC,QSA,S=2]
RewriteRule ^(?!user\.php).*/$ /user.php?display_name=$0 [NC,QSA]

RewriteCond %{HTTP_HOST} ^es\.example\.site$ [NC]
RewriteCond %{QUERY_STRING} !language=es [NC]
RewriteRule ^.*$ /$0?language=es [L,QSA]

1 Answer 1

1

You're probably trying to achieve this:

RewriteEngine On

RewriteRule ^home/?$ /index.php [NC,QSA,S=3]
RewriteRule ^(contact-us|our-location|gallery)/?$ /$1.php [NC,QSA,S=2]
RewriteRule ^(?!user\.php).*/$ /user.php?display_name=$0 [NC,QSA]

RewriteCond %{HTTP_HOST} ^es\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} !language=es [NC]
RewriteRule ^.*$ /$0?language=es [L,QSA]
Sign up to request clarification or add additional context in comments.

6 Comments

What a speedy and efficient answer! The revisions for the non-subdomain rules work perfectly. But the subdomain rules are throwing up 500 internal server errors for some reason.
Sure. I'm getting repeat lines of this: "Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace."
@awl19 Updated the rules again. Please check
Made the changes. No more errors and using the subdomain is properly using the get variable, but for whatever reason the "sub-folder" proceeding the domain is using the user.php rule instead of the rule specified. In other words, es.example.com/home is really coming out to something like example.com/user.php?display_name=home&language=es instead of example.com/index.php?language=es
@awl19 increment the values of each S= in the rule by 1. I'll run some tests on my own server as well. BTW, which apache version are you using?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.