URL Aliasing using .htaccess - php

I have a directory 'Domainname1/folder/'. In Domainname1, I have a sub-directory which is a sub-domain (abc.mydomain.com) of another domain. This is a reference to 'domainname1/folder/'. The thing is I want the URL links accessing 'domainname1/folder/' to display the sub-domain definition. So instead of seeing:
'domainname1/folder/'
They see:
'abc.mydomain.com/path'
How can I do this?

you should use a reverse proxy to do such setup, here a basic howto.
Hope this would help you

You can use the proxying abilities of mod_rewrite to achieve this. In the VirtualHost section for abc.mydomain, you can add:
RewriteRule (.*) http://mydomain/folder/$1 [P]
ProxyPassReverse / http://mydomain/folder

Related

Domain Masking and Path Forwarding

I need to direct my domain www.abc.com to www.xyz.com/folder/form/ and pass parameters to the form, but I need to mask the path so that when users go to www.xyz.com that's all they see along with any passed parameters in the url. Is the possible? How can I achieve this?
I do not own both domains. I own www.abc.com and the folder in www.xyz.com, but not the naked domain. The domains are on different servers.
I have tried the solution setting the DNS to *.abc.com and the CNAME to www and www.xyz.com. But, CNAME's do not allow pointing to a path. If I do a 301 or 302 forward the domain is not masked. What else can I do. I've been pouring over this for days.
Few ways to achieve url masking without using DNS setting.
On server level: Setting up reverse proxy.
If you are using apache, you can use the module named mod_proxy.
Once you have enabled the module, Add following to your .htaccess which is in your abc domain root.
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.example.com/folder/form/
ProxyPassReverse / http://www.example.com/folder/form/
Another way to achieve similar result would be, as follows which does pretty much same thing under the hood.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com$ [NC]
RewriteRule ^ http://www.example.com/folder/form/%{REQUEST_URI} [L,P]
On language level: Using a scripting language like php and then pipe the data to and fro via. the second domain using curl. Kinda mix of 'man in the middle attack" and "phishing". But most importantly, it's pretty much possible.
Then we have other run of the mill solutions like using <iframe>. etc.

.htaccess direct domain to subdirectory

I am trying to redirect www.example.com to /example/ on my webserver, but it appears to only be redirecting the index.php page. An additional issue is the main file displays as http://tunedu.com/tunedu/ when I would like it to display as tunedu.com
Live example:
This page works: http://tunedu.com/tunedu/
This page doesn't work: http://tunedu.com/school.php?id=75
Any regex changes I do try end up just breaking everything. The .htacess code is this:
RewriteEngine on
RewriteRule ^$ /tunedu/ [L]
Thanks.
The proper way to do such a thing is by setting VirtualHosts on your webserver (either Apache, nginx or another...). Using htaccess for this seems quite painful.
Assuming you're using Apache, here's a useful link: http://httpd.apache.org/docs/current/vhosts/examples.html
I'm not sure why you are not using VirtualHost to set that up.
But in case you want to go the mod_rewrite way here is an useful link:
http://httpd.apache.org/docs/2.2/rewrite/vhosts.html
I hope that helps.

.htaccess Rewrite "external" subdomain to subfolder if match

Lets say i have wildcard subdomains on an external domain, can be anything like
demo.site1.com
blah.site1.com
and have directories like these on an external websites
external.com/websites/demo.site1.com
external.com/websites/blah.site1.com
and i want to make it so that all requests for lets say demo.site1.com should rewrite to
external.com/websites/demo.site1.com if the subdirectory matches demo.site1.com
NO REDIRECTION, I MUST KEEP THE URL THE SAME...
I have to do this for multiple subdomains with the same kind of subdirectories.
Is it possible to do?? if not is it possible without matching???
I read the apache .htaccess docs over and over for the past 12 hours and can't seem to
figure out a way how to do it.
Your help will mean alot to me...
You should configure Your domain in domain administration panel to point at this addresses.
If You don't have access to them use iframe, but as far I know .htaccess doesn't provide this kind of functionality.
try this. put it inside htaccess on site1.com document root. it work only if both domain has permission to access together
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.site1.com/(.*)$
RewriteRule ^(.*)$ external.com/websites/$1.site1.com/$2 [L]

How to create a subdomain with username as subdomain name?

I have referred other related question but they are not clear to me. Please explain me: How can I make subdomain in PHP?
Example :
http://www.domainname.com/page.php?usname=sundar
I want change the link to this
http://sundar.domainname.com
Is this possible in PHP? Or any other way to do it?
You may create a virtual sub domains and then you can redirect it with .htaccess.
You also have to create
A Record look like this
*.exmple.com A 127.0.0.1 or your IP
in your DNS.
Then add something like this in your .htaccess
RewriteRule ^([aA-zZ])$ home.php?username=$1
RewriteCond %{HTTP_HOST} ^(^.).mywebsite.com
RewriteRule (.) home.php?username=%1
It should help
my way:
you will have to create a wildcard subdomain and point it you your domain.
http://www.easymodrewrite.com/example-subdomains
Then you can parse $_SERVER['HTTP_HOST'] for querying out the user name .
if you are under hosting plane, you can probably create it from the GUI.
Else, you need to via the APACHE panel and configure the DNS.
You could use .htaccess url rewrite to make that.
Just rewrite www.(username).site.com to www.site.com/profile/(username)
the code for that would be something like..
RewriteRule ^(.*).site.nl site.nl/profile/$1
if my memory serves me right

Multiple domains for site subsections

Here's the deal. Basically I've got multiple domains, and I would like one of the domains to point to the regular base of the site, but the other domains to point to a subsection of the site without modifying the url in the address bar. The idea is that each of the extra domains are branded for their section.
Example:
www.domain.com Top level of site
www.domain2.com points to www.domain.com/abc
www.domain3.com points to www.domain.com/def
etc.
Also note that in the example 'abc' and 'def' are not real directories on the filesystem, but are virtual areas defined in a database.
I've spent quite a bit of time looking around and couldn't find anything that fits this. I do not want to use domain cloaking because it uses frames. Regular redirects obviously are easy to point to the right thing, but they change the url in the address bar.
Is there any way to accomplish this?
Edit:
I've added the alias as Mark suggested below, but can anyone shed light on how I could then use mod_rewrite to make this work?
First, your DNS records need to point to the IP of the web server.
Second, you have to set up Apache to serve multiple domains from the same VirtualHost. Enable mod_alias and then use the ServerAlias directive in your VirtualHost definition. For example:
ServerName www.domain.com
ServerAlias domain.com www.domain2.com domain2.com www.domain3.com domain3.com
If you've done that correctly, you should see the exact same content at each domain, without any redirection.
What you do next is an architectural decision. You can use mod_rewrite to hard-code URL routing rules based on domain, or you can use PHP to do the routing, based on the value of $_SERVER['HTTP_HOST'].
A mod_rewrite solution might involve adding something like this to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} domain2\.com$
RewriteRule ^(.*)$ /abc/$1 [L]
RewriteCond %{HTTP_HOST} domain3\.com$
RewriteRule ^(.*)$ /def/$1 [L]
This is a high-level overview. Please comment on my answer if you need details on a particular part of the process.

Categories