Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 1st, 2008, 10:09 AM
rishijd rishijd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 286 rishijd User rank is Lance Corporal (50 - 100 Reputation Level)rishijd User rank is Lance Corporal (50 - 100 Reputation Level)rishijd User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 6 h 5 m 16 sec
Reputation Power: 5
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!

Reply With Quote
  #2  
Old May 1st, 2008, 11:27 AM
rockurchin rockurchin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Location: Los Angeles
Posts: 43 rockurchin User rank is Lance Corporal (50 - 100 Reputation Level)rockurchin User rank is Lance Corporal (50 - 100 Reputation Level)rockurchin User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 49 m 55 sec
Reputation Power: 1
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]

  1. Make sure apache rewriting in on
  2. if the url isn't an existng directory
  3. or if the url isn't an existing file
  4. load contoller.php instead. In controller.php you can parse the url and pass the variables to your other scripts

Hope that helps a little

Reply With Quote
  #3  
Old May 5th, 2008, 10:06 AM
rishijd rishijd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 286 rishijd User rank is Lance Corporal (50 - 100 Reputation Level)rishijd User rank is Lance Corporal (50 - 100 Reputation Level)rishijd User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 6 h 5 m 16 sec
Reputation Power: 5
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!

Reply With Quote
  #4  
Old May 5th, 2008, 02:30 PM
rockurchin rockurchin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Location: Los Angeles
Posts: 43 rockurchin User rank is Lance Corporal (50 - 100 Reputation Level)rockurchin User rank is Lance Corporal (50 - 100 Reputation Level)rockurchin User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 49 m 55 sec
Reputation Power: 1
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;

}

Reply With Quote
  #5  
Old May 6th, 2008, 04:27 AM
rishijd rishijd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 286 rishijd User rank is Lance Corporal (50 - 100 Reputation Level)rishijd User rank is Lance Corporal (50 - 100 Reputation Level)rishijd User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 6 h 5 m 16 sec
Reputation Power: 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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > Htaccess file for multiple subsites sharing the same PHP code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway