I have been looking for a while now to find a solution to accomplish the following system.
I would like to build a PHP system on, let's say, domainA. On this domainA I will allow an administrator to 'create' a new website. This website contains only of pieces of text, which are all stored in a database. This, I know how to do.
However, now I would like to make it possible that visitors that surf to domainB will be invisibly redirected to for example domainA.com/gateway.php?refdomain=domainB&page=xxx or something similar.
I have a vague idea this should be done by .htaccess, but I don't really know how I can do this in the most easy way. If for example there are some POST or GET requests on domainB, this should keep working. Also images linked to http://www.domainB.com/test.gif should be invisibly loaded form www.domainA.com.
I also know there are some CMS systems (eg drupal) which allow this feature, so it is possible, I just don't know how.
Thank you for any advice that might point me in the right direction,
kind regards,
Digits
Are you hosting both of these on the same machine? If so, something like VirtualHosts in Apache could solve this for you.
mod_alias and mod_rewrite might also be of some use to you.
Basically, you'll want to point all your domains to the same directory (maybe using a wildcard in your vhosts) and then setup urlrewrite; look at this question for an example, and it can be in a .htaccess file or Apache configuration.
All requests that come in will go to the same gateway.php and you can extract the current domain and requests using $_SERVER['REDIRECT_QUERY_STRING'], $_SERVER['REQUEST_URI'] and $_SERVER['SERVER_NAME'] for example. See $_SERVER. You'll then be able in your gateway.php to send the correct files.
If you use a CMS like Drupal, you should be able to assign these using the Portal Alias. By using the alias you will be able to assign different domains to point to different "sites" that are created.
OK, here's a really simple example:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domainA\.com
RewriteRule (.*) http://www.domainA.com/gateway.php?realpath=$1 [L,QSA]
You could then parse "realpath" in your gateway script using parse_url and take the appropriate actions.
You could get more complex with your rewrite rules to have separate ones for images, etc. if you wanted to
You could use the redirect header..
Related
i read the other threads about this topic but i couldn't find anything that i felt could apply in my case. It seams pretty basic though. I have a website built in php with apache server. In this moment all the traffic is done via http. The people who paid for the site, now want to move it to https. They bought a certificate and the web server hosts will install it. What changes do i need to make to make it work via https, besides changing the redirects within the code?
I also found this link which seems pretty helpful, but i think maybe it's too complex?
Thank you,
Alex
You should change your resource links (like external JavaScript references such as jQuery) in the site where there are hard-coded paths in http://domain.name/some-link-here to just //domain.name/some-link-here. This will prevent the browser from complaining about mixed-mode content.
For links that are on the same domain, you could use absolute/relative URLs.
After that you can place and .htaccess such that any URLs accessed on the domain would automatically redirect to the HTTPS version. Place the following lines as the first rule in the file
.htaccess code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The .htaccess will also take care of any hard-coded links (towards the same domain/site) that you might have in your site and that you have missed.
I am making a template for a website and want every page to be passed through a single php file to allow for both easy page editing and elegant, intuitive URLs. I have a standard Linux webhosting package and want so that when the user visits http://example.com/language-x/a-page-called-foo then the sever invokes and returns the output from http://example.com/template.php?page=a-page-called-foo&language=language-x without the user seeing anything to do with tamplate.php in the address bar. Is there some standard way to do this so I don't have to contact my webhosting provider and asking for them to tweak the way the server is working?
Assuming you are using Apache with mod_rewrite enabled as your webserver, what you can do is create a .htaccess file in your application root. The content of this file should, roughly, contain something like this:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
You can read more about this subject here http://www.desiquintans.com/cleanurls
Try to learn basic Regular Expressions patterns, as this is used for matching your URLs. http://regexone.com/
We have a php project / php web-application where users can create profiles which more or less looks like a website on a sub-domain URLs like robert.blogger.com. Now this user also has a domain of his own example robert.com. Now we want every request for robert.com to redirect to robert.blogger.com without changing the URL.
The URL should show robert.com/home.html, robert.com/aboutus.html etc. but actually code should be run from robert.blogger.com/index.html, robert.com/aboutus.html etc.
Please note that the project is hosted on a dedicated server with dedicated IPs & we also have access to the Control Panel of the user's domain.
We have tried htaccess but that only redirects, we want masking / mapping to work.
Is this possible? If so, how can this be done? Would appreciate much !!!
The solution would depend on what kind of server software you're running, but in Apache you'd do this by mapping the default vhost for the IP to the application (and then letting people point their domain to that host), and in your application use HTTP_HOST in $_SERVER to look up the valid domain (which you're probably already doing to map the subdomain to user accounts). This would be the exact same thing, as long as you keep all links relative in your HTML (and don't think "i mapped it to this user, so the domain should be user.example.com").
To give a more specific answer you'd have to be more concrete in your question.
It should be possible to use ProxyPass in htaccess, if you have permissions to use it. Try something like this.
ServerName robert.com
RewriteRule ^/(.*)$ http://robert.blogger.com/$1 [L,P]
Or you can map it in your application, depends if that server is yours and you can do anything you want to setup.
I understand that there may be other questions regarding vanity urls but everyone i see has a different code that i guess does the same job. Therefor i do not understand what rules are best for my personal question, that being said here is my question.
I simply want to create this,
127.0.0.1/website/profile.php?id=1
To this,
127.0.0.1/website/profile/Admin
My sub questions are also,
I understand the .htaccess file has to be in the root directory, but is that the root of my website or my xampp htdocs?(e.g c:/xampp/htdocs/ or c:/xampp/htdocs/website)
Using php should i make the conversion between id to username for the URLS on a seperate file then redirect to the requested user's page?
Thank you for reading, i just can't seem to get my head around .htaccess!
Root directory of your website.
No need for redirects. The way it works is that you can map every section of your URL to a URL parameter. For example, http://localhost/profile/Admin is really interpreted as http://localhost/website/profile.php?username=Admin. Only users will see the vanity URL; PHP will still see the URL parameters. In your case, the .htaccess rule will look something like ^profile/([0-9]+)$ profile.php?username=$1 (I obviously don't know for sure since I don't know the architecture of you site).
On a side note you might find Virtual Hosts interesting. It's a way of being able to create your own local domain for your site, for example http://my-local-website instead of using http://localhost/website or waiting to test in production.
More info here: http://sawmac.com/xampp/virtualhosts/
On of my client asked me to create an Web App in PHP, I ended up using Symfony. At delivery, he told me that he has distributed a software with an embedded Web view pointing to a hardcoded url :
www.domain.com/dir/tools.php
Now he wants the Web app to appear in it's Web View, but the software isused by about 400 customers, we can't expect the hard coded URL to be changed.
How do you think I can do that in clean way :
Create www.domain.com/dir/tools.php and use a redirection ? Which one and how ?
Use URL rewriting ? Any snippets appreciated, I have no Idea how to do that.
Apache mod_rewrite:
RewriteEngine on
RewriteRule ^dir/tools\.php$ new_page.php [R=301]
EDIT: As noted, this goes in your .htaccess file. The mod_rewrite documentation I linked has more information. Fixed .
In your Apache configuration for the host or in a .htaccess file, you can do a redirect:
Redirect 301 /dir/tools.php http://www.example.com/whatever
Use URL rewriting.
URL rewriting is implemented with a couple lines of configuration in your web server software. It is not implemented in your own web application, so you would not be using PHP to implement it. You will be telling your web server that any request that comes in asking for "/dir/tools.php" will be modified, before it ever hits your PHP web application, to ask for whatever URL you want it to ask for. For example, you can specify that any request asking for "/dir/tools.php" be rewritten to ask for "/my-custom-dir/my-tools/" instead.
Each web server implements URL rewriting differently. Often, the web server will not support that feature with a minimal out-of-the-box feature set, but through an addon that you can install. You should consult the documentation for your web server to find out how to configure it to perform URL rewriting.