Have site with many languages
extra languages are in subdomains on my server like de.mydomain.com, fr.mydomain.com.
in these de,fr subdirectory i've placed only htaccess file with this code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.de\.mydomain\.com$
RewriteRule ^(.*)$ "http://www.mydomain.com/$1?lan=2%1" [L]
And it works but not how I want. it simply redirects from de.mydomain.com to mydomain.com, url in the browser is changing and I would like the url to stay like: de.mydomain.com but the content to be taken from mydomain.com?lan=2.(i use lan variable to change lang)
what do I do wrong here?
maybe my general aproach to this problem is wrong?
Edit :
You need to point de subdomain to the root directory instead, and then adding these lines to the root htaccess file :
RewriteCond %{HTTP_HOST} ^(www\.)?de\.mydomain\.com$
RewriteRule ^(.*)$ /$1?lan=2 [L,QSA]
Put this rule before your rule:
RewriteRule !^(fr|en)/ /en%{REQUEST_URI} [L,R=301]
.htaccess rewrite to default language folder?
Related
help me please.
I have several php files in root
domain.com/dog.php
domain.com/cat.php
...
When user go to dog.domain.com i need to show domain.com/dog.php but keep dog.domain.com in browser URL
I already have this .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*).domain.com$
RewriteRule .* http://domain.com/%1.php [L]
It works fine and show domain.com/dog.php content when I type dog.domain.com, but now it changes URL in browser to domain.com/dog.php
How to solve it?
P.S. Wildcard DNS record turned ON (already catch all subdomains *.domain.com)
If *.domain.com is defined within the same vhost you have to use a relative RewriteRule there: RewriteRule ^.*$ /%1.php [L]). If not, you have to replace [L] by [P] and make sure that you have mod_proxy loaded. See https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html
Last but not least, you might want to update your RewriteCond to be case insensitive: RewriteCond %{HTTP_HOST} ^(.*).domain.com$ [NC]
I have the following .htaccess code that successfully rewrites subdomain directories. So if a user visits jim.domain.com they get served placeholder.php?page_type=profile. However, this also affects the main directory http://domain.com. I'd like it so that anything with a subdomain is directed to the placeholder.php page, but using the main directory with no subdomain would act as usual, going to the index.php in the main directory. How would I achieve this? Thanks for any advice.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^exclude.domain.(.*)
RewriteCond %{HTTP_HOST} !^www.domain.(.*)
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule ^$ placeholder.php?page_type=profile [L,QSA]
If your wanting all requests for test.domain.com to go to domain.com/placeholder.php?page_type=profile as in your comment then you need to include the domain in the rewrite
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^exclude.domain.(.*)
RewriteCond %{HTTP_HOST} !^www.domain.(.*)
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule ^$ http://domain.com/placeholder.php?page_type=profile [L,QSA]
this will not how ever deal with this part
but using the main directory with no subdomain would act as usual, going to the index.php in the main directory
because you have no file/directory miss rules that redirect to index.php. Do you need those, or really just want to solve the first part?
I also wonder if your wanting profile replaced with the subdomain match, in which case you want
RewriteRule ^$ http://domain.com/placeholder.php?page_type=%1[L,QSA]
but both of these examples will not rewrite any path of test.domain.com/longer_url because the ^$ is only matching an empty URL path. But how you want to handling paths needs to be decided before a suitable Reerite can be proposed.
I have a little problem in hands.
I am setting up a domain that as 3 languages, example.com for principal domain, en.(...) for english and de.(...) for germany.
Usually I only redirect the httpdocs from the subdomains to the main with ln -S because all languages executes the same code, the difference is matched from php and mysql.
My new host don't provide any ssh connection so I have to use a different approach on this.
It was told to me that it can be done by .htaccess but I already tried a lot of things but only can redirect, changing the url and that's not possible, it have to keep the same, the contents yes, will be from another domain. Can someone help?
This code should looks like the one you're searching for :
www.domain.en .htaccess
RewriteBase /
RewriteRule ^(.*)$ http://www.domain.com/en/$1 [L,R=301]
www.domain.de .htaccess
RewriteBase /
RewriteRule ^(.*)$ http://www.domain.com/de/$1 [L,R=301]
You'll propably adapt the http://www.domain.com/lang/$1 part to your needs.
EDIT
Following your comment, this is a code for subdomains redirections :
domain.com .htaccess
RewriteCond %{HTTP_HOST} ^en\.domain\.com [NC]
RewriteRule (.*) http://domain.com/en/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^de\.domain\.com [NC]
RewriteRule (.*) http://domain.com/de/$1 [QSA,L]
Damn you modrewrite
I have a website hosted at a url like:
http://mydomain/mocks/thesite/
Now I want to move it to a new domain
http://thesitesdomain.com/
My htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule (.*) http://www.thesitesdomain.com/$1 [R=301,L]
Now this works fine as long as there is something after /mocks/thesite/. eg: http://mydomain/mocks/thesite/index.html redirects to http://www.thesitesdomain.com/index.php.
However the problem is that:
http://mydomain/mocks/thesite/ redirects to http://thesitesdomain.com/mocks/thesite/. Any idea why? How to stop this?
The .htaccess file is in the root of /mocks/thesite/ (if that helps)
Thank you
You should try to use the variable REQUEST_URI you might have a little more success with that. It should be the request uri and file name. To
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI} [R=301,L]
I can't remember but to also redirect with the query string (get variables) I think you need to add it like this.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
Been a while since really doing a domain redirect....
BTW this is a good read on htacces configuration:
http://corz.org/serv/tricks/htaccess2.php
I'd like to redirect a website from http:// domain.com & http:// www.domain.com to http://v2.domain.com, while maintaining access to http:// (www.)domain.com/images/*
I've tried several methods but somehow I can no longer access the /images folder anymore.
P.S: both subdomain & root has different content/CMS. Any ideas as to how to implement this?
Thanks
You haven't explained exactly how these are configured. I'm going to assume that www.domain.com and v2.domain.com are different virtual hosts:
You should be able to do this in your .htaccess file or apache configuration for www.domain.com:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !images/
RewriteRule ^/(.*) http://v2.domain.com/$1 [L,R]
I realised something like this could work as well. Probably need some testing, but if this is wrong do comment.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{HTTP_HOST} !v2\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://v2.domain.com/ [R=302,L]