I am using joomla 3.3, I have a site on which user can create their own store with domain name so how can I create sub domain by which user can access their sub domain.
Suppose if a user create abc.example.com then that user should be able to access abs.example.com
So how to do this.
i have added these lines to .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.zzphonecase\.com(.*)$ /index.php/%2/%1
and these lines in index.php file of template
$host = explode ('.', $_SERVER ['HTTP_HOST']);
$subdomain = $host [0];
if((!strcasecmp ($subdomain, 'www')) || (!strcasecmp ($subdomain, 'zzphonecase')))
{
//main site enter code here
}
else
{
//enter code here
// subdomain
http_response_code (404);
echo 'Error 404 : your domain could not be found';
return false;
}
The problem is when and where you load the domain redirect. you're loading it at the template layer...way too late in the process. it has to be loaded before the joomla framework is loaded (top of root index.php. i use "virtual domains" for multisite domain management, and fabrik for custom forms & components extensively on my sites. you could create a form in fabrik that adds and entry & parameters to the virtual domain database table. little bit of a learning curve on how to execute it, but once you get it this will make it very simple for you. You can then setup your wildcard domain and point it to the site root and let the virtual domains component do all the work for you. Seriously...multisite management in joomla is a real pain. others have done the work for you!
Related
I have three websites. Each is a folder and accessible like:
example.com/siteA
example.com/siteB
example.com/siteC
A category and product may exist in those sites like:
example.com/siteA/category/subcategory/productABC
I have 3 new urls, under 2 domains.
siteA = https://www.newsiteA.com
siteB = https://www.newsiteB.com
siteC = https://www.newsiteB.com/siteC
The problem is redirecting the old urls and their contents, to the new url while also redirecting with www and https. I cannot get them to all work together.
An example of a desired redirect:
http://example.com/siteA/categoryA/*contents*
to
https://www.newsiteA.com/categoryB/*contents*
contents being anything after that url.
I've been trying via htaccess (of a magento site) but dont mind doing it via another method.
Suggestions are greatly appreciated.
Try these rules as very first rules in your root .htaccess:
RewriteEngine On
RewriteRule ^siteA(/.*)?$ https://www.newsiteA.com/$1 [L,NC,NE,R=301]
RewriteRule ^siteB(/.*)?$ https://www.newsiteB.com/$1 [L,NC,NE,R=301]
RewriteRule ^siteC(/.*)?$ https://www.newsiteC.com/$1 [L,NC,NE,R=301]
The question is simple:
I have had a temporary domain name to put a website live before changing the current hosting of the client (for various issues with previous hosting).
So the website was live for a while using a bad URL, like:
http://www.morphartsolution.com/tau2015/
It stayed like this a few months, google put the bad URL in search results. Now that the website is live at:
http://www.marchestau.com
I would like to remove any reference to morphartsolution.com/tau2015/ . In order to do this naturally I thought to do a .htaccess redirect from morphartsolution.com/tau2015/ to marchestau.com but couldn't work it out properly.
Both morphartsolution and marchestau domains are in the same hosting (server), morphartsolution being the main domain name and marchestau an additionnal domain that works inside the tau2015/ folder.
Any clue as what would be the magic line to put in .htaccess for this?
Thanks!
You need a permanent redirect from
http://olddomain.com/tau2015/
to
http://www.marchestau.com
Add the following line to your htaccess :
Redirect 301 /tau2015 http://www.marchestau.com
If the above redirect fails, try mod-rewrite :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldddomain.com$
RewriteRule ^tau2015/(.*)$ http://www.marchestau.com/$1 [NE,L,R=301]
I think you want to redirect every page at http://www.morphartsolution.com/tau2015/ to http://www.marchestau.com/ as it is , for example , http://www.morphartsolution.com/tau2015/example.php to http://www.marchestau.com/example.php
So put the following code inside htaccess # tau2015 folder
RewriteEngine On
RewriteRule ^(.*)$ http://www.marchestau.com/ [R=301]
I have a userprofile system in which a dynamic page (profile.php) changes as the id of user changes..
For eg. profile.php?id=2 displays the profile of user having id=2.. But i want the address to be as user/user_name.php. So providing each user a unique profile-page address..
Is it possible without creating a seperate page for each user?
Thnx
Ok, let´s talk about apache´s mod_rewrite. Basically what people usually do is that they setup one php page eg. index.php and redirect all the requests there (except those that request existent files and directories) and index.php then routes these requests to proper files/presenters/controllers, etc.
I´m gonna show you a very simple example how can this be done, it´s just to give you the idea how it works in basics and ofc there are better ways to do this (for example take a look at some framework).
So here is the very simple .htaccess file, placed in the same directory as index.php:
<IfModule mod_rewrite.c>
RewriteEngine On
# prevents files starting with dot to be viewed by browser
RewriteRule /\.|^\. - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?query=$1 [L]
</IfModule>
And here is the index.php:
<?php
$request = explode("/", $_GET["query"]);
// now you have your request in an array and you can do something with it
// like include proper files, passing it to your application class, whatever.
// for the sake of simplicity let me just show you the example of including a file
// based on the first query item
// first check it´s some file we want to be included
$pages = array("page1", "page2", "page3");
if(!in_array($request[0], $pages)) $request[0] = $pages[0];
include "pages/".$request[0];
But I highly recommend you not to reinvent the wheel and take a look at some existing php framework. You´ll find out that it saves you a lot of work, once you learn how to use it ofc. To mention some - Zend Framework, Symfony and the one I´m using - Nette Framework. There are many more, so choose whatever suits your needs.
I am running into the following issue:
Our members have a desire for personalized sites directly from our primary domain in the form of http://www.example.com/membername. I am looking at possibly solutions in two ways but neither are ideal (will be explained below).
Method 1 - ?Member=
In this method, I simply create a custom URL and store the information in the member's database profile. For example: if I want my "custom" URL to be jm4, for a consumer to visit my site, they must type in http://www.example.com?Member=jm4.
The site, of course, does a $_GET['Member'] to lookup the member information, stores the primary data in Session from the index page, then redirects to a homepage. The consumer no longer sees the membername in the URL but instead sees all the page names for www.example.com as if they simply visited the parent domain to start (each member's page has custom information however).
While this method works it presents the following problems:
The URL is not nearly as easy as /jm4
and any errors typing out the
wildcard ?Members= will result in
page error. Also, This method keeps
that particular member's information
in session (which is necessary
browing from page to page on that
particular member domain) and
prevents somebody from simply typing
http://www.example.com?Member=name2 to
visit another site without clearing
their session or closing the browser.
Method 2 - /membername
While the preferred method, currently the only way we know how to create is to manually generate an index file in a subfolder, redirect to the primary index then allow the consumer to view the member's personal site.
For example, if I visit www.example.com/jm4, I am hitting the /jm4 folder which contains index.php. Within this file simply contains:
<?php
session_start();
ob_start();
$_SESSION['AgentNumber'] = "779562";
header("Location: ../index.php");
exit;
?>
the primary index recognizes this with:
<?php
session_start();
ob_start();
if ($_SESSION['MemberNumber'] == NULL) {
header("Location:ac/");
exit;
}
$conn = mysql_connect("localhost", "USER", "PW");
mysql_select_db("DB",$conn);
$sql = "SELECT * FROM table WHERE MemberNumber = $_SESSION[MemberNumber]";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
$_SESSION['MemberName'] = $newArray['MemberName'];
$_SESSION['MemberPhone'] = $newArray['MemberPhone'];
$_SESSION['MemberMobile'] = $newArray['MemberMobile'];
$_SESSION['MemberFax'] = $newArray['MemberFax'];
$_SESSION['MemberEmail'] = $newArray['MemberEmail'];
$_SESSION['MemberAddress'] = $newArray['MemberAddress'];
$_SESSION['MemberCity'] = $newArray['MemberCity'];
$_SESSION['MemberState'] = $newArray['MemberState'];
$_SESSION['MemberZip'] = $newArray['MemberZip'];
$_SESSION['MemberAltName'] = $newArray['MemberAltName'];
}
mysql_close($conn);
header("Location: home/");
exit;
?>
We would certainly prefer to use the second method in terms of 'ease' for the member but keep running into the following issues:
We are forced to manually create a
sub-folder and unique index.php file
for each new member we onboard
While the above probably could be
automated (when new member creates
profile, automatically generate php
file and folder) but this is more
complicated and we don't want to
have 3000 subfolders on the primary
domain.
Has anybody run into similar issues? If so, how did you go about solving it? What would you recommend based on my details above? Any advice is appreciated.
Also - using as subdomain (membername.example.com) is not preferred because our current SSL does not allow for wildcards.
EDIT 1 - EXISTING .HTACCESS FILE
My existing .htaccess file on the site looks like this for reference:
ErrorDocument 404 /404.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(.*)$ /?Member=$1 [L]
You can do your prefered method by just adding some lines to the .htaccess in your root directory:
This site should get you started
Or this one
If you are using apache, then you could use mod_rewrite to change urls like http://host/membername to http://host/memberpage.php?name=membername.
You could use this in a .htaccess file for your second method. It will rewrite http://yoursite.com/membername to http://yoursite.com/?Member=membername
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /?Member=$1 [L]
</IfModule>
I'm trying to match subdomains to a customer id in symfony.
i.e. i have customer1.example.com and customer2.example.com
Domains are stored in a table.
When a user goes to customer1.example.com, I would like to get the subdomain, look up the domain name in the database, once matched, it will then deploy the app config for that customer and then store the customer_Id in a global attribute so i know exactly which customer I'm dealing with througout the whole application. The virtual host will have the relevant wildcard servername.
Have you managed to achieve this, and if so, how? If not, any ideas would be a great help!
I'm thinking about using a filter to do it.
:-)
also going to be needing yo set your domain as a wildcard domain, if not you going to need to create manually each subdomain per client.
another solution that is not so symphony dependent is using a .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule (.*) $1?sub=%2&page=$1&domain=%{HTTP_HOST} [QSA,L]
<IfModule>
that code basically will send to the requested page the subdomain, the domain and the page requested. then in php you can check if it is equal to your client username. and allow you also to use parked domains for your clients at the same time.
i hope it helps.
Take a look at sfDomainRoutePlugin - it does what you want. However, in its current version you don't get the Propel or DoctrineRoute functionality, which means you must manually lookup the customer based on the subdomain parameter returned from the plugin. Example:
app/frontend/config/routing.yml
# pick up the homepage
homepage:
url: /
class: sfDomainRoute
param: { module: homepage, action: index }
requirements:
sf_host: [www.example.com, example.com]
# catch subdomains for customers
customer_subdomain:
url: /
class: sfDomainRoute
param: { module: customer, action: index }
app/frontend/modules/customer/actions.class.php
public function executeIndex(sfWebRequest $request)
{
// get the subdomain parameter
$this->subdomain = $request->getParameter('subdomain');
// retrieve customer (you have to create the retrieveBySubdomain method)
$this->customer = CustomerPeer::retrieveBySubdomain($this->subdomain);
}
This is just an example, but I use a similar approach myself, and the plugin does what is advertised. Good luck.
If you're adventurous, yuo could take a look at Chapter 2 in the "More with symfony book". This would help you understand the code in sfDomainRoutePlugin.
Because you want to load different app, filter won't help. Just use the frontcontroller (index.php) to extract the subdomain, and if the app directory exists, load the app (else 404). You can even store the id in app configuration.
I'm doing something similar. Note, I haven't tried this exact setup.
$tokens = explode('.', $_SERVER['SERVER_NAME'], 2);
$app = $tokens[0] == 'www' ? 'default' : $tokens[0]; //assumes you aren't allowing www.app.example.com, change if you are
try
{
$appConfiguration = ProjectConfiguration::getApplicationConfiguration($app, 'prod', false);
}
catch(InvalidArgumentException $e) //thrown if app doesn't exist
{
$fallbackConfiguration = ProjectConfiguration::getApplicationConfiguration('default', 'prod', false);
$context = sfContext::createInstance($fallbackConfiguration);
$request = $context->getRequest();
$request->setParameter('module', 'default'); //set what route you want an invalid app to go to here
$request->setParameter('action', 'invalidApplication');
$context->dispatch();
}
if (isset($appConfiguration))
{
sfContext::createInstance($appConfiguration)->dispatch();
}