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]
Related
I want my site to act like this. If user inputs site.cz it should be redirected to site.eu/?lang=cs but the user should still see site.cz. Right now I have the following htaccess file:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://site.eu/?lang=cs [L,R=301]
which works great and redirects only .cz request (dont do anything with .eu requests) but it displays .eu/?lang=cs in final. Problem is that I dont only want to display site.cz all the time but also links like site.eu/folder1/file1/?lang=cs should be redirected to site.cz/folder1/file1/
Any ideas how to accomplish this?
Thanks in forward
Are you using XAMPP or a web host? Upon testing, URL rewriting isn't working in XAMPP.. Anyway, you can try to check this, just make sure that your two sites are hosted by the same web hosting account:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteRule ^(.*)$ http://site.eu/$1?lang=cs [P,L]
But it looks like your sites aren't hosted by the same hosting account as what you've said:
when I use [P] flag I get an error "Following URL was not found on this server" – horin
Recently I moved my websites to the hoster one.com. They have setup an automated mechanism (I dunno what they use to achieve that) to rewrite any first-level folder on the webspace to a subdomain.
I.e. the folder http://example.com/folder1/ will be also available as http://folder1.example.com/
Now, I have a site, that is using quite a lot javascript to include pages from a hardcoded, static source. Due to the SOP the scripts are working depending on which hardcoded reference they use.
So, to make sure that everybody gets a working version of the website, i wanted to redirect the direct folder access to the subdomain as well.
My htaccess for this - which is working localy and on various htaccess-testers out there - seems to be not working with one.com:
RewriteEngine On
#Rewrite Access to folder1-folder to subdomain.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/folder1.*?$ [NC]
RewriteRule .* http://folder1.example.com/ [R=301,L]
Since I don't know the exact mechanism one.com is using to achieve the mentioned behaviour it might just be a conflict with my rules.
Support says, that all the used commands are fully supported, and therefore wasn't be able to tell what's going wrong...
Does anybody have encountered something similiar and has a hint for me?
just fiured out the solution:
RewriteEngine On #does not work
vs.
RewriteEngine on #does work
You need to check that the actual request was made for /folder/ and not the URI (which can internally be rewritten). Try:
#Rewrite Access to folder1-folder to subdomain.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /+folder1/ [NC]
RewriteRule ^folder1/(.*)$ http://folder1.example.com/$1 [R=301,L]
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]
My website was on a subdomain, like this: mysite.primarydomain.com. The primarydomain.com DNS was managed by a third party who owns the primarydomain.com url.
My new website is now on on mysite.com. I had the third party add an a record that points mysite.primarydomain.com to my new website's IP address. How can I then redirect that mysite.primarydomain.com domain to mysite.com? Would that be via htaccess? Or via cpanel configuration?
Thanks!
There's probably a cpanel configuration to do this pretty easily, probably something like this: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/WHMDocs/SetupForwarding
But you can also add an htaccess file to the document root of the mysite.primarydomain.com site, that says:
Redirect 301 / http://mysite1.com/
or if the document root is shared, you'll need:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\primarydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mysite1.com/$1 [L,R=301]
Thanks Jon Lin for your answer. It inspired me to find a very easy method in cpanel...
In the primarydomain.com, I created a subdomain for "mysite.primarydomain.com".
I then went to "Redirects". Since I added the "mysite." subdomain, it gave me the option to create a redirect using that subdomain. So I created a redirect for mysite.primarydomain.com to point to mysite.com.
I then was able to create a few other redirects to help keep some of their old links live, such as "mysite.primarydomain.com/about".
Thanks!
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.domain\.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
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