.htaccess rewrite with dots - .htaccess

I'm looking for a way to do something like this in .htaccess:
This.is.my-website.com
Please note: This.is is the rewrite to the directory This.is and mywebsite.com is the URL of the site. I want all requests to the site to be redirected to that folder (301?). Is it possible to achieve this in .htaccess?

Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.my-website.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
for an internal rewrite (won't change the URL in browser's address bar).
Or to externally redirect:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.my-website.com$ [NC]
RewriteRule ^(.*)$ http://my-website.com/%1/$1 [L,R=301]

Related

redirect to a wildcard subdomain with htaccess file

I already added a subdomain wildcard to my dns (*.domain.com) but now i can't get the rule right.
I want
subdomain.domain.com
to point to
domain.com/subdomain
my htaccess file is :
RewriteEngine On
RewriteCond %{HTTP_OST} ^(?:www\.)?((?!www\.)[^.]+)\.(domain\.com)$ [NC]
RewriteRule ^/?$ http://www.%2/%1 [R=302,L]
but i'm getting Internal Server Error.
How can i get it to work ?
If you want it to actually redirect then you can do this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/subdomain/$1 [R=301,L]
If you don't want it to redirect and keep subdomain.example.com in the address bar then, you can do this.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^(.*)$ /subdomain/$1 [L]

How to redirect webmail to a new url?

need to redirect webmail.domain.com to a new url (google mail). i have tried with this code on .htaccess
code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !https://webmail.domain.com/$ [NC]
RewriteRule ^(.*)$ https://mail.google.com/a/domain.com/$1 [L,R=301]
but here, the whole site is redirecting to new url. https://domain.com is redirecting. i just want only the webmail url https://webmail.domain.com/ to redirect.
how to do it?
Remove "http://" from the Left side of HTTP_HOST string
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^webmail.domain.com$ [NC]
RewriteRule ^(.*)$ https://mail.google.com/a/domain.com/$1 [L,R=301]

Add a value to a url with htaccess

I have a big issue here.
I have a site example.com, due to the way it was coded, example.com is different from example.com/index. How can i use htaccess to redirect all incoming request from example.com to example.com/index
Here is what i've tried to do but it's not working
The first i did was
RewriteRule ^(.*)$ http://%1/index/$1 [R=301,L]
The second was
RewriteRule ^/index/([^/.]+)/?$ index.php [L]
I'm not so familiar with htaccess though. Any help?
Thanks
NOTE there are so many domain the .htaccess file is working for and i want the rule to affect all e.g example.com should go to example.com/index, example1.com should go to example1.com/index and ... like that
And i already have this rule on top RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
You can use this single rule in the website root .htaccess:
RewriteEngine On
RewriteRule ^/?$ /index [L,R=302]
This will redirect:
example.com => example.com/index
example1.com => example1.com/index
RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteRule ^(.*)$ http://example.com/index.php/$1 [R=301,L]

.htaccess redirection to specific url

I moved my site from blog.abc.com to www.abc.com
I want to redirect every request made to blog.abc.com to abc.com
For example:
If blog.abc.com/example.html is requested, it should redirect to www.abc.com/example.html, how can I do it via .htaccess only?
You can put this code in your htaccess (in blog.abc.com root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
Using mod_rewrite you could do it like this:
RewriteEngine On
RewriteCondition %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
or if blog.example.com has its own vhost you could also use mod_alias:
Redirect / http://example.com/

(.htaccess) 301 redirect with same url structure

I use 301 redirect from non-WWW to WWW domain! Works fine, but links are different.
Example:
from - ggkj.com/posts/godzilla/43
to - www.ggkj.com/index.php?view=posts&author=godzilla&aid=43
my .htaccess 301 redirect code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*) http://www.example\.com/$1 [L,R=301]
.htaccess code: http://pastebin.com/t3FA59uq
This is currently what i use on my website with success:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} !^www.walterbax.ca [NC]
RewriteRule ^(.*)$ http://www.walterbax.ca/$1 [R=301,L]
EDIT: after looking into your question a little further I can tell you that your issue is improperly placed in the file. it must be hitting another rule that is rewriting it into URL variables.
I would start with a basic htaccess for the www. rule for testing and add to it from there.
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

Resources