htaccess problem - .htaccess

at the moment I have 2 domains pointing at the same webspace (so domain1.com/index.html and domain2.com/index.html give the same page). I'm trying to configuer it so that if I go to domain1.com/index.html or domain1.com/test/... I get forwarded to domain1.com/something/index.html or domain1.com/something/test/...
When I go to domain2.com/index.html it shouldn't get forwarded so I should just see domain2.com/index.html
Any suggestions how I can do this?

This is Untested:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule ^(.*)$ /something/$1

Related

Multiple Rewrite Conditions on multiple Domains with .htaccess-File

I'm using a Webserver which is reachable via 2 Domains, eg. exa_mple.com and example.com. Let's assume, exa_mple.com is quite complicated so I'd like to redirect all traffic coming from exa_mple.com to example.com. Also, I'd like to force them to use https. That worked fine so far:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exa_mple\.com [OR]
RewriteCond %{HTTP_HOST} ^example\.com [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [L]
Now when I try to open http://www.exa_mple.com/testfile.html, I actually reach https://www.example.com/testfile.html, which is absolutely brilliant. But now my task is to also make sure, this works with subdomains, so eg. testfile.exa_mple.com should lead to https://testfile.example.com and still point to the right folder.
SSL is available for all subfolders, I just need help finding the right Rewrite-Conditions. Allready tried lots of things, resulting in Server-Errors or non-working Rewrite-Conditions. Thanks for any help!

Change subdomain link to another and keep content

I have 2 sub-domains, if the user navigate to sub-domain 1, keep the content, but change the URL to sub-domain 2. The following is not working for me, not sure about the best way of implementing this.
RewriteCond %{HTTP_HOST} ^sub1.domain.com
RewriteRule ^(.*) http://sub2.domain.com/$1 [P]
I found the solution for this issue, I hope this will reach someone needs it.
RequestHeader set Host sub1.domain.com
RewriteRule membership/new-member-application/$ http://sub2.domain.com/member/newmemberapp/ [P,L]

htaccess rewrite rule for subdomain results to redirect loop

Below is my htaccess config
RewriteEngine On
# if the domain starts with "apply."
# i.e. apply.domain.com
# redirect to application URI
RewriteCond %{HTTP_HOST} ^apply\. [NC]
RewriteRule !^formwizard /formwizard/apply [R=301,L,NC]
I have tried it, and when I go to http://apply.domain.com/ it successfully redirects to http://apply.domain.com/formwizard/apply.
My problem is, once it redirects to that URI, it goes to a redirect loop.
Can anyone please help hit me what is wrong with my config?
Background:
I have 3 subdomains: www.domain.com, apply.domain.com, and admin.domain.com. It all references to the same source codes and just managed by my htaccess.
Once the person goes to apply.domain.com, it should be redirected to the application page which is /formwizard/apply.
PS. I don't want to depend too much on the backend codes because I believe this is a server config problem.
Thanks in advance!
If there are more rules then this rule might be getting impacted by them. Modify this rule to this:
RewriteCond %{HTTP_HOST} ^apply\. [NC]
RewriteCond %{THE_REQUEST} !/formwizard/ [NC]
RewriteRule ^ /formwizard/apply [R=301,L,NC]
Also make sure this is very first rule below RewriteEngine On line.

Redirect all subdomains using .htaccess

What I want to achieve is to redirect any subdomain.mydomain.info to mydomain.info/subdomain using a 301 so that the visitor still sees subdomain.mydomain.info.
After some research I found that I had to set wildcard in my A-Record, did that. Than I went on to create a .htaccess. Below is my entire .htaccess.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.info [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.info [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
When I open subdomain.mydomain.info where I know that mydomain.info/subdomain is an existing folder I only get a message telling me that the domain "subdomain.mydomain.info" is unavailable.
My webspace is running a Confixx panel, just if that helps.
What could be going wrong here?
At this point I am guessing that some configuration outside the .htacces need to be made, but no idea what and where.
BIG EDIT:
Revisiting this. Turned out I had to talk to my provider to get some things set up correctly. Still trying to figure this our though.
Current situation: the .htaccess from above gives me a 500. Putting in an R, als was suggested in the comments, will redirect "sd.domain.info" to "domain.info/sd/sd/sd/sd" and result in an error by my browser. The browser says "There is redirect on this page" and give me the option to load it again. The version suggested by Al Kafri Firas also gives me a 500. When I remove the .htaccess any "subdomain.doamin.info" gets redirected to "domain.info" with the URL being changed in the head of my browser.
Still looking to get this working....
Revert all changes you made to your A-Record and use this rules
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.info$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.example\.info$ [NC]
RewriteRule /%2%{REQUEST_URI} [PT,L]

.htaccess - subdomain not working with www

I see a lot of questions about it here on SO, so I'm posting here:
I have a domain www.example.com and I have set .htaccess file to redirect all example.com to www.example.com
Now, I made (through my plesk 10 interface) a subdomain abc.example.com and what I would like is to also have www.abc.example.com so I entered (also in plesk) this:
www.abc.example.com. CNAME abc.example.com.
But it's not working. Do I need to reload/restart dns?(if so, please tell me how?) Or do I just need to wait certain time for this until it propagates?
Since my mentioned CNAME didn't work, I also added the .htaccess (which might be wrong (i know, not much of a server person :( )) in the abc folder which looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^abc.example.com$
RewriteRule ^(.*)$ http://abc.example.com/$1 [R=301]
but with no luck, so please shed some light.
The solution which worked for me in the end:
In Plesk I made one subdomain.domain.com pointing to lets say abc folder, and then I added the www.subdomain.domain.com also through Plesk but pointed it to the same abc folder. Then I added the .htaccess file inside this abc folder (where all other files for this subdomain reside) which now guarantees that all requests to subdomain.domain.com get redirected to www.subdomain.domain.com. Here is my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.subdomain.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.subdomain.domain.com/$1 [R=301,L]
Hope this will help someone beginning with this stuff like me.
Just to note, the credit for the idea of pointingthe www.subdomain inside the same folder goes to user Bryan White on serverfault
.htaccess should be like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^abc\.example\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://abc.example.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} !^abc\.example\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://abc.example.com/$1 [R=301,L]
However DNS entry for abc.example.com and www.abc.example.com might not have been propagated. You need to give it sometime (few hours may be) before you test this.
You can use nslookup on Windows or *nix to check when is your domain is available to the world.

Resources