Keeping the original subdomain url in the address bar - apache

How can I change my rewrite rule to keep the original subdomain url in the address bar?
Currently if it type in "username.domain.com" it gets redirected to "domain.com/username"...and I would like the address bar to stay at "username.domain.com".
I'm using wildcard subdomains with this rewrite rule in my httpd.conf file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule . http://domain.com/sites/%2 [L]
</IfModule>
Is this even possible?
Thanks in advance.

Related

Mask subdomain using .htaccess

I want to mask my subdomain to a specific url on my main domain using .htaccess.
For example: https://sub.example.com to show the content of https://www.example.com/page/12345.
And the URL is still https://sub.example.com
I have got the following in .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com
RewriteRule ^https://sub\.example\.com https://www\.example\.com/page/12345
But if I go to https://sub.example.com, it shows content of https://www.example.com. Can't seem to figure out what's wrong. Please help!
Actually, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.
Then, the rewrite should look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
#only when there is query string and https on, if needed
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTPS} =on
RewriteRule ^$ https://www.example.com/page/12345? [R=301,NE,NC,L]
Reference:
What exactly does the Multiviews options in .htaccess?
htaccess rewrite without redirect
Apache: RewriteRule Flags

.htaccess rewrite to redirect domain.com to domain.net/subdirectory

I would like to redirect somedomain.tv to anotherdomain.com/tv and (if possible) keep the URL as somedomain.tv
My .htaccess so far:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^radiouas\.tv$ [OR]
RewriteCond %{HTTP_HOST} ^www\.radiouas\.tv$
RewriteRule ^/?$ "http\:\/\/www\.radiouas\.org\/tv" [R=301,L]
</IfModule>
# This simply redirects but does not keep the original URL
I have found many ways to do that when you have only one domain (e.g. domain.com to domain.com/blog). But in my case, I'm using two different domains...
How can I achieve that? Thanks in advance.

.htaccess old domain to a new domain not working when structure page IS NOT the same

I have this on my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://www.houstonhouseandhome.net/$1 [R=301,L]
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.houseandhomeonline\.com$ [NC]
RewriteRule ^(.*)$ http://www.houstonhouseandhome.net/ [R=301,L]
The homepage goes to the new domain, but the subpages of the old domain are not going to the index of the new domain. they go to the new domain and look for the very same page, is there a way that the requests from the old domain pages go to the new domain index?
Thank you,
For some reason you've got two sets of rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://www.houstonhouseandhome.net/$1 [R=301,L]
</IfModule>
And then
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.houseandhomeonline\.com$ [NC]
RewriteRule ^(.*)$ http://www.houstonhouseandhome.net/ [R=301,L]
You only need the first set. The [L] flag tells apache to stop processing any more rules if this one matches. Since it will match everything, the second set of rules will never take effect.
To to stop everything trying to find a relative page on the new domain, you simply remove the $1 from the end of the domain. So your htaccess file will look like this:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://www.houstonhouseandhome.net/ [R=301,L]
</IfModule>
Note
Since you're using 301 redirects, make sure your browser has cleared its cache/history before retesting. Browsers will not request an url it thinks will respond with a 301.

Redirect subdomain to another subdomain

i want to know how could i redirect subdomain to another subdomain and also different domain name
for example
i want to redirect subdomain
forum.example.com
to
forum.example.net
thanks
This code should work for you. you need to add a redirect to your .htaccess file.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.net/$1 [r=301,nc
Another good, but lazy way is to use the following link, to genereate the code for you htaccesss generator
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^forum\.example\.com$ [NC]
RewriteRule ^ http://forum.example.net%{REQUEST_URI} [R,L]

htaccess redirect from domain1 to domain2

I know, this should be easy, but I cannot make it work.
I have 2 domains pointing to the same folder in an Apache server, bahiadivers.com and bahiadivers.cl.
I want to redirect bahiadivers.cl to bahiadivers.cl/es/ and change the address bar.
I try this (among a million things)
rewritecond %{HTTP_HOST} ^bahiadivers.cl [nc]
rewriterule ^/$ http://www.bahiadivers.cl/es/$1 [r=301,nc]
but didn't work... I mean, the URL is not changing in the browser address bar, but also the languge (/es/) is not working... how should I do this?
Thanks!
Try this for your .htaccess
# Apache configuration file
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
# If URL is www.example.com/es/Blah, use /Blah/
# Prevents needing to change existing links.
RewriteBase /es/
# Rewrite www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www.bahiadivers.cl
RewriteCond %{HTTP_HOST} ^bahiadivers.cl
# Rewrite any inbound URL Bits to http://bahiadivers.cl/es/...
RewriteRule (.*) http://bahiadivers.cl/es/$1 [R=301,L]
</IfModule>
That should do it.