|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Htaccess file for multiple subsites sharing the same PHP code
Hi,
I just posted a question here: http://forums.devshed.com/php-devel...url-527335.html - basically I am setting up a site which will be divided into subsites, one per country (for a set number of countries). The sites will be the same (the coding must be shared), but the content will vary depending on the site ID or code, for example, the following URLs should work for my site..and the key difference would be the SITE ID as you can see below (which will show different content from a database, based on that site id): http://www.mydomain.com/in/ http://www.mydomain.com/sg/ http://www.mydomain.com/in/browse.php http://www.mydomain.com/sg/browse.php http://www.mydomain.com/in/ads/cars/36/ http://www.mydomain.com/sg/ads/cars/37/ The recommendation on the previous post was to simply using htaccess to do the redirection, but I want to do this for EVERY page (i.e. different php scripts, more importantly different URLs like the above, some of which require rewrites themselves) My question is, how would I do this.. . Let's say my current htaccess file looks like this: Code:
RewriteEngine on RewriteRule ^ads/(.*)/(.*)/(.*)$ view.php?range=$1&style=$2&$3 [L] RewriteRule ^ads/(.*)/(.*)$ view.php?range=$1&style=$2 [L] RewriteRule ^viewpage/(.*)/(.*)$ viewpage.php?sef_url=$1&$2 [L] RewriteRule ^viewpage/(.*)$ viewpage.php?sef_url=$1 [L] Basically, different rewrites will be used for the site. Now, I want everything with a SITECODE in front of the URL to be 'secretly' redirected to scripts like the above - the point being to 1) Identify the site code, and therefore what content the visitor wants to see (i.e. content for that region) 2) Use the same PHP scripts so that there's no redudancy... I thought this could be a start, but it would mean I need to alter all my redirects above to accept a new parameter.. any recommendations on a 'best practice' approach for this? Code:
//not tested- just a thought to start... RewriteRule ^(.*)/(.*)$ http://www.mydomain.com/$2/sitecode=$1 [L] Many thanks! |
|
#2
|
|||
|
|||
|
Below is an htaccess file I use regularly to do things just like this
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /controller.php [QSA,L]
Hope that helps a little |
|
#3
|
|||
|
|||
|
Thanks so much, I tried this and it works. So, in controller.php, I guess you are using code like this:
Code:
$aux_request_uri = substr($_SERVER['REQUEST_URI'], 1); //strip off first character, which is a slash
$aux_url_elements = explode("/",$aux_request_uri); //e.g. yourdomain.com/this/that/ will result in an array with 0=>"this", 1=>"that", 2=>""
while(list($key,$val)=each($aux_url_elements)) {
//process the array and include the correct php file etc.
}
If this is somewhat different to how you would code it (since I can imagine a lot of coding for a complicated website with many different types of URLs) - then I'd really appreciate some advice or a sample of code to see how you would do it.. Many thanks! |
|
#4
|
|||
|
|||
|
That's pretty much what I'm doing. I get the path and put it in an array...
Code:
$url = parse_url($_SERVER['REQUEST_URI']);
$path = explode("/",$url['path']);
foreach($path as $k => $v){
if ($v != ""){
$app[] = $v;
}
}
Then I have a series of switch statements, something like this Code:
switch($app[0]){
case "x":
$var1 = $app[1];
$var2 = $app[2];
include "x.php";
break;
case "y":
$var1 = $app[1];
include "y.php";
break;
default:
include "404.php"; //Page not found
break;
}
|
|
#5
|
|||
|
|||
|
Thanks very much!
This has led me to another question regarding $_REQUEST variables (namely $_GET) and I have posted a separate post here: http://forums.devshed.com/php-devel...tml#post2036260 If you have experienced this problem before please let me know. Many thanks for your help! |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > Htaccess file for multiple subsites sharing the same PHP code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|