So I'd like to use a htaccess file to forward a domain:port onto another domain:port
In this case I'll use this example of what I want to achieve
DomainA.co.uk --> DomainB.co.uk
DomainA.co.uk/* --> DomainB/*
DomainA.co.uk:8000/* --> DomainB:8000/*
even better would be able to forward any and all ports on like so
DomainA.co.uk:*/* --> DomainB:*/*
Thoughts would be greatly appreciated,
Thanks
Henry
Addition : The OS i am running is cPannel/WHM 60.8 on CentOS
Redirecting a domain wholesale can be achieved with directive Redirect
Redirect / http://DomainB.co.uk
or to domain B with port 8000
Redirect / http://DomainB.co.uk:8000
You can use the following RewriteRule :
RewriteEngine on
RewriteRule ^ http://domainB.com:%{SERVER_PORT}%{REQUEST_URI} [NE,L,R]
Related
I have a website setup at mydomain.com/FR
I'd like to make sure people typing
mydomain.com/fr are being sent to mydomain.com/FR
mydomain.com/fr/aNyTHiNg are being sent to mydomain.com/FR/anything
... whether they type http, https or http(s)://www.
How would I do that using .htaccess ? I'm afraid this is too much of a complex rule for me to sort it out.
You can use this simple rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^fr(/.*)?$ FR$1 [L]
I've searched all over the internet, finding multiple answers to achieve a redirect, but none have ever been 100% full-proof. I need a .htaccess subdomain redirect that works in every circumstance:
"protocol://mysite.com/" → "protocol://subdomain.mysite.com/"
"protocol://www.mysite.com/" → "protocol://subdomain.mysite.com/"
"protocol://mysite.com/folder/" → "protocol://subdomain.mysite.com/folder/"
"protocol://www.mysite.com/folder/" → "protocol://subdomain.mysite.com/folder/"
I know it's possible, but I can't find any good documentation on it, let alone documentation on the .htaccess fundamentals.
Try this (placing as the first rule on your .htaccess Rewrite section
RewriteCond %{HTTP_HOST} !^subdomain.yourdomain.com$
RewriteRule ^(.*) http://subdomain.yourdomain.com/$1 [R=301,L]
note remember changing both subdomain.yourdomain.com to your desired subdomain url and restart apache.
note 2 Change to https:// if your desired destination is also a https domain
note 3 for TEMPORARY redirects, change "R=301" to "R=302"
EDIT some helpfull links about apache .htaccess
http://www.tecmint.com/apache-htaccess-tricks/
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
I'll be quick on what im trying to do,
basically I have a user profile page that will be my url, let's say,
profile.php?user=alex
So now what is working fine in my .htaccess file is changing that into
website.com/alex
for quicker access.
For other purpose, I would need that to be basically
alex.website.com
but I couldnt figure out a way to rewrite my URL to that, instead of having a subdomain for every user.
If you have any idea if it's possible & how I would go on doing this, I would appreciate it alot!
Thank you
Alex
To just rewrite the URL path, try this rule:
RewriteRule ^[a-z]+$ profile.php?user=$0
If your user names have a different syntax, replace [a-z] as you need.
For rewriting the host, try this rule:
RewriteCond %{HTTP_HOST} ^([a-z]+)\.example\.com$
RewriteRule ^$ profile.php?user=%1
Note that this will only rewrite //alex.example.com/ internally to //alex.example.com/profile.php?user=alex. Additionally, your server will already need to be configured that it accepts any subdomain of your domain (see ServerAlias and name-based virtual hosts).
I want to redirect from:
domain1.com/photos
To:
domain2.com/photos
I want the URL in the address bar to still read:
domain1.com/photos
Is there a way to do this using only .htaccess?
Note:
My .htaccess file for domain1.com is currently completely blank.
No, there isn't a way to do this with .htaccess. Doing so would present a glaring security hole - imagine someone doing this with a bank's website!
If both are hosted on the same server, do this in your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule (.*)$ http://www.domain2.com$1 [P]
</IfModule>
If you own both domain1 and domain2, you could accomplish this through domain name forwarding. Check your domain name registrar (like godaddy.com) for the options.
No, you can not do it through htaccess file.
You could open an iframe in domain1.com/photos that shows the contents of domain2.com/photos. But then the url would never change from domain1.com/photos, even when you went to a different page in domain2.
What are you trying to do? It sounds very sketchy. Do you own both domains? Why would you want to duplicate the contents of one site at another address?
Why is this not possible? Seems like a reasonable task as long as your Apache has mod_proxy installed:
ProxyPass /photos http://domain2.com/photos/
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass
A way around it, if the page at domain.com/photos is a server side script, do an HTTP call and serve up the response.
In ColdFusion:
<cfhttp url="another.domain.com/photos">
<cfoutput>#CFHTTP.FileContent#</cfoutput>
They'll be an extra request, but it'll get you the output you want.
its impossible using htaccess file.
Hi I'm quite new to PHP... And need something to do as fast as I can..
I have some clients within the "clients" directory like here...
"http://domain.com/clients/client0001/fluids/..."
I want this URL to be shown in the address bar like this.
"http://client0001.domain.com/fluids/..."
with the help of .htaccess. Any help will be appreciated ...
Thanks
You can use mod_rewrite to rewrite such URLs:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$
RewriteRule !^clients/ clients/%1%{REQUEST_URI} [L]
But your webserver needs to be configured so that it accepts such host names and sends the requests to the proper virtual host.
I've used this before as posted by Gumbo.
Only issue I've had with it is that you can't then use further rewrite rules - so if the site you are serving on the subdomain uses url rewriting, you have to make it its own virtual host.