I am trying to make functionality described as follows:
example.com will load content from webhosting_root/com/ but URI stays example.com
example.es from webhosting_root/es/ , URI: example.es
example.pl from webhosting_root/pl/ , URI: example.pl
example.cz from webhosting_root/cz/ , URI: example.cz
...
All domains are set to route to one webhosting.
I think this is achievable by .htaccess rules? But i am not sure how to do this. Can you please help?
Found solution:
.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
RewriteCond %{REQUEST_URI} !^/com/
RewriteRule (.*) /com/$1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?example.es$
RewriteCond %{REQUEST_URI} !^/es/
RewriteRule (.*) /es/$1 [L]
...
Related
In cPanel (at subdomain management) I've set up a wildcard like to following:
*.example.com > public_html/subDomainHandler
Every (non existent subdomain) request like abc.example.com redirects properly to example.com/subDomainHandler.
But requests like abc.example.com/subfolder doesn't redirect to example.com/subDomainHandler.
I am not at my best in regular expressions, but can anybody give me a RewriteCondition for .htaccess?
Htaccess Rewrite Rule - Try1
I think your answer could be modeled on https://stackoverflow.com/a/8481076/1688441 .
Try the following:
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com\(.*)
RewriteRule ^(.*)$ http://example.com/subDomainHandler/$1 [R=301]
Try2
Another option:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
RewriteRule (.*) http://www.example.com/subDomainHandler%1 [R=301,L]
From: https://webmasters.stackexchange.com/questions/13475/redirect-rewrite-subdomain-to-subfolder
I did many way to do this, but always getting 404 error.
I want to redirect subdomain
[username].domain.com/
to
domain.com/user/[username]/index.php
and the url on browser address is not changed still
[username].domain.com/
[username] is dynamic according to registered user in my site.
my last trial httaccess setting is
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(^.*)\.domain\.com$
RewriteRule ^ ^.domain.com/user%{REQUEST_URI} [L,P]
Note: I did set my DNS wildcard *.domain.com
Thanks in advance,
Nanang K
============================================================
SOLVED
I had to create 3 htaccess files.
in root directory (redirect to user)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*)$ /user/$1 [NC,L]
in user directory (redirect to username_folder)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([aA-zZ])$ user/$1/index.php
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule (.*) user/%1/index.php
in username_folder directory (rewrite the url into original url)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([aA-zZ])$ index.php?siteName=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule (.*) index.php?siteName=%1
now, when user access robert.domain.com, he will get the content from domain.com/user/robert/index.php. And the url browser still robert.domain.com
hope helps someone who get similiar problem.
Hello Can you please try this :-
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /users/$1 [L,NC]
It may use helpful.
It should be like this, try it out.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[username].domain.com$
RewriteRule ^/?$ "http\:\/\/domain\.com\/users\/" [R=301,L]
hope this helps!
I have a link: http://testsite.com/api/v2/1
I would like to point my browser to: 1.testsite.com and using redirection in .htaccess link it to this place: http://testsite.com/api/v2/1
How can I do this?
Try this :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.testsite\.com$ [NC]
RewriteRule ^$ http://testsite.com/api/v2/%1 [L]
I have two domains that point to the same webserver:
example.cz
example.de
I need:
example.de → example.de/de (but can't be see in address field: example.cz/de)
If it ends up showing in the URL like example.de/de it's OK, but the best solution is just example.de and from server load example.de/de.
I've tried with this:
RewriteBase /
RewriteCond %{HTTP_HOST} example.de$ [NC]
RewriteRule ^$ example.de/de [L,R=301]
but after I click on something on the page I get: example.cz/de and this is problem.
You can use an inner rewrite without R=301 redirect, if you use LAMP server, in /.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} (www\.)?example\.de$ [NC]
RewriteRule ^$ /de/index.php [L]
You'll see in address bar: http://example.de but not http://example.de/de .
Add this to redirect http://example.cz/de to http://example.de .
RewriteCond %{HTTP_HOST} (www\.)?example\.cz$ [NC]
RewriteRule ^de$ http://example.de [R=301,L]
my site (domain.com) is now located into /var/www/
and you can also access it directly through its IP: 88.88.88.88
I would like to obtain:
when user enter the IP : 88.88.88.88, it redirects to 88.88.88.88/reboot/
if user enters the full domain name, it shows the site as it does now.
I tried with .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} 88.88.88.88
RewriteRule .* http://88.88.88.88/reboot/ [R=301,L]
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule .* http://www.mysite.com [R=301,L]
does not work good:
www.mysite.com :GOOD
mysite.com: GOOD
88.88.88.88 ->redirects to 88.88.88.88/reboot : GOOD
but then it generates an error: Error 310 (net::ERR_TOO_MANY_REDIRECTS)
Any clue ?
When you're on 88.88.88.88/reboot, your HTTP_HOST is still equal to 88.88.88.88.
Try adding a RewriteCond rule depending on the REQUEST_URI, which will redirect everything that is not /reboot to /reboot :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} 88.88.88.88
RewriteCond %{REQUEST_URI} !^/reboot/
RewriteRule ^(.*)$ http://88.88.88.88/reboot/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule .* http://www.mysite.com [R=301,L]
The ERR_TOO_MANY_REDIRECTS comes because your rule loops.
Whenever a request comes to host 88.88.88.88 , you redirect it to 88.88.88.88/reboot/ , but /reboot/ uri is also on that host, so it redirects again and loops.
If you only want to redirect / to /reboot/ on host 88.88.88.88 , you need to alter your RewriteRule to this:
RewriteCond %{HTTP_HOST} 88.88.88.88
RewriteRule ^/$ http://88.88.88.88/reboot/ [R=301,L]
If, however, you wish to redirect everything outside of /reboot/ , then you need to add a condition (RewriteCond):
RewriteCond %{HTTP_HOST} 88.88.88.88
RewriteCond %{REQUEST_URI} !^/reboot/
RewriteRule ^/$ http://88.88.88.88/reboot/ [R=301,L]
(keep the rest of the rules intact).