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]
Related
Been struggling with this problem for a while now.
We have a basic online app which you can access at say
app.domain.co/signup?user=onlinestore
onlinestore is the username of the account.
We want each user to get their own subdomain that they can use the app from.
In this case the subdomain would be onlinestore.domain.co/signup and it would show them the contents as if they were here: app.domain.co/signup?user=onlinestore.
Now as well as that subdomain mirroring the login pages, when they login I would like for all of the pages inside of the app to be able to use the subdomain as well. Ideally I don't want the user to see the app.domain.co domain at all, just their personalised domain. Theres quite a number of pages inside the app so im not sure if theres a simple way for them all to be accessible from any subdomain (if logged in ofc).
Examples:
onlinestore.domain.co will become app.domain.co/signup?user=onlinestore
onlinestore.domain.co/payments will become app.domain.co/payments?user=onlinestore
onlinestore.domain.co/contact will become app.domain.co/contact?user=onlinestore
Current HTACCESS File (in the wildcard subdomain)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.co$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).domain.co
RewriteRule ^$ https://app.domain.co/signup/?user=%1 [L]
We've created a wildcard subdomain but it's not working with https, and it's doing a full redirection as opposed to a rewrite, I'm still on shared hosting so I'm not sure if I might have some restraints due to this.
Is there a simple way to do this? I don’t want the users to see the app.domain path at all, just their custom subdomain path.
I have a problem:
I have to modify an application written in Zend 1 that was deployed to the domain root. now to test it the customer gave me a root subfolder called [domain]/social
When I run it, I have a lot of problem because all paths are like "/resource", but in this case the fiddler show me that the request look for [domain]/resource ad not for [domain]/social/resource.
It happens with script sources, ajax urls, hrefs...all!
Is there a way to fix the problem?
I am not quite familiar with Zend, but is there a main config file that sets the application root folder? (Like joomla) You can modify that if it exists.
Other option would be to preg_match or str_replace all instances of the domain name in the code ( like when moving a Worpress site) but you should definately do that with a sample content not couple hundred pages).
And here is a htaccess snippet as well:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/social/$1 [R=301,L]
Be sure to put the htaccess under the development folder not under the root, oterwise you're facing issues.
I suggest cheking for a config file first. Hope one of this helps!
I've been looking at htaccess and how to use rewrite rules in order to make a sort of "fake subdomain" for users.
so far i have:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([a-z0-9-]+)/? http://$1.domain.com [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^([a-z]+)\.domain\.com$
RewriteRule ^$ index.php?user=%1
this will take any /somthing and make it a subdomain and then pass the subdomain value in as a param to pick up.
i want to be able to now use actual parameters, and pass them through normaly with the extra "user" param from the "subdomain"
e.g.
fred.domain.com/index.php?page=1&sort=up
would give me in $_GET
['user'] = 'fred'
['page']= 1
['sort'] = up
but for the life of me I cant figure out how to do this! as when i add any other params, I loose the user bit
Any help? =)
Also any helpful tutorials on htaccess would be nice! as all ones ive found haven't really explained what each bit does and why =\
Thanks in advance
.htaccess file has nothing to do here. It can't help you.
To direct a user to your server, you have to alter DNS record, not web-server config.
I am assuming that:
You own a domain, domain.com say, that is being hosted by some shared hosting service (SHS) provider.
You either have access to a control panel to set up subdomains, or your SHS provider has already set up a * A record mapping to its shared service.
Some SHS providers simply map *.domain.com to a fixed subdirectory, say /webroot/domain.com/public_html; others do this top level-redirection for their users and provide a control panel which allow account-holders to associate subdomains with specific subdirectories.
So you need to work out which applies in your case:
by looking at your SHS providers FAQs,
by trying http://sss.domain.com/ to see if it routes to your DOCROOT
by using a phpinfo() script to see what Rewrite environment variable it uses to point to your DOCROOT. (For technical reasons in Apache, see Dynamic mass virtual hosts with mod_rewrite, %{DOCUMENT_ROOT} cannot be properly initialised for each user, so providers typically use a RewriteMap to initialise a stand-in; mine uses %{ENV:DOCUMENT_ROOT_REAL})
So let's assume that you want to set up a blog at say http://blog.domain.com/, you may need to:
Issue permanent redirects [R=301] from legacy references to http://domain.com/blog/* to http://blog.domain.com/*
Issue internal redirects from http://blog.domain.com/* to DOCROOT/blogdir/*
Add the necessary conditional interlocks to prevent infinite redirection loops, where this second internal redirect is then treated as a legacy reference.
I could give you a set of rewrite rules to do this, but given that I've answered a dozen flavours of this same Q this months, you can find lots of templates by searching or by looking at my blog (Webfusion, .htaccess) where I've written a number of articles giving more explanation.
If you want a single application to catch some wildcard subset of domain, as long as you can encode this in a regexp then you can do something like:
RewriteCond %{HTTP_HOST} (sompattern)\.domain\.com
RewriteRule ^(?!appdir/).* appdir/catchall.php?arg=$0&subdomain=%1 [L,QSA]
The (?!appdir/) bit is called a lookahead negative assertion and this stops the rule refiring on itself.
I'm pretty sure you can set vhost *.yourdomain.com to point to a single path and then use mod_rewrite for the url parsing.
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
In my project I have to make a subdomain, i.e
if the user name is XXX when he register, a sub domain will be created like XXX.example.com
how to do it?
I will use php for scripting.
I found a script that seems to do exactly that, create a subdomain on your server on demand.
It probably needs a little bit of tweaking for it to work on your particular control panel, but the review are quite positive as far as I can tell.
Link
Have you considered using htaccess and url rewriting?
Found this code that may help you:
# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
#
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]
Source (Post #6)
This might be a little more complex than you think.
I suggest to do some reading on mod rewriting and htaccess.
You could start here:
htaccess Tutorial
Modrewrite tutorial
Subdomain Modrewrite Example
EDIT: Or just go with one of the nice examples provided my fellow SO users. ;)
As long as this is for non-SSL sites, then by far the easiest way is not to bother - just use a wildcard DNS domain and vhost, then map any domain specific behaviours in your PHP code. If you need SSL sites then its a lot more complicated - you need to have a seperate IP address/port for each certificate - and woldcard certs can be very expensive.
If you're wanting to set up some sort of hosting package then its a bit more involved - how you go about this depends on what webserver and DNS server you are using.
Assuming (again no SSL) with Apache on Unix/POSIX/Linux and bind, then, again I'd go with a wildcard DNS entry, then:
1) create a base dir for the website, optionally populate this with a default set of files
2) add a vhost definition in its own file in /etc/httpd/conf.d named as XXX.conf
3) send a kill -HUP to the HTTPD process (causes it to read the new config files without having to do a full restart).
One thing to note is that you really shouldn't allow the httpd process direct write access to its own config files - you definitely don't want to give it root privileges. A safer solution would be to create a CLI script to perform this using the username as an argument then make it setuid and invoke it from the script run by the HTTPD process.
C.
the best way is to use a joker in your DNS server :
www.example.com. IN A 1.2.3.4
*.example.com. IN A 1.2.3.4
By this way, No subdomain has to be created : all are pointing to the same IP by default.
In your PHP code, you just have get $_SERVER["HOST"] and get the fist part :
$hostParts=explode('.',$_SERVER["HTTP_HOST"]);
$user=$hostParts[0]
First, you need to make sure you have a wildcard domain setup in DNS, and make sure your webserver (apache?) directs all queries for that wildcard domain to your php file.
Then in php you can look at $_SERVER["HTTP_HOST"] to see which subdomain is used for that particular request.
Since you will make sub-domains when an user registers.
Try this as .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^.htaccess$ - [f]
RewriteCond %{HTTP_HOST}!^www.domain.com
RewriteCond %{HTTP_HOST} ^([^.]+).domain.com
RewriteRule ^$(.*) /$1/%1 [L]
make a function of a controller which will take the value of sub-domain and display what necessary.
like::
public function show ($domain)
{
**.**..*..**.** Your code goes here
}
when a user will try this xxx.domain.com/controller/show this will be domain.com/controller/show/xxx . if you want to xxx.domain.com to be domain.com/controller/show/xxx just edit the htaccess file as you want.