Welcome Guest, Not a member yet? Register   Sign In
Development Environment Setup
#11

[eluser]dtrenz[/eluser]
I'm curious what specifically you need to change in the config?

I play with my local host file a lot for testing. (c:\windows\system32\drivers\etc\hosts)

or I use switch statements that flip based on local server ip.
#12

[eluser]Pygon[/eluser]
jleequeen:
switch vs if is really a non-issue. 9 times out of 10 you are talking about micro-optimizations that account for a difference of a millisecond over 100,000 iterations -- hardly worth mentioning. Also -- php_uname was suggested by MadZad.

dtrenz:
Well, my local environment, versus testing, versus production environments all have different databases, different hostnames, etc -- I find it easier to remove these configuration (app related but server dependant) from the application development directory as it makes it far easier to upload to each environment
#13

[eluser]Daniel Eriksson[/eluser]
If you are using ..\system32\etc\hosts to redirect the site to your local machine for testing/development then you end up having to edit that file quite often.

A better way (imho) is use the hosts file to set up an alternate name for the local instance of the site.

www.sitename.com points to the live server (resolved through DNS as usual)
www.sitename.local points to the local machine (127.0.0.1, resolved through ..\system32\etc\hosts)

If you are using CI then you also need to modify the base_url setting, otherwise CI will generate URLs that point to the live server. Here is an easy way to do this if your Apache server name is set properly:

Code:
$config['base_url'] = "http://" . $_SERVER['SERVER_NAME'] . "/";

/Daniel
#14

[eluser]dtrenz[/eluser]
i'm not sure that works if you're using VirtualHost directives.
#15

[eluser]Daniel Eriksson[/eluser]
[quote author="dtrenz" date="1206479031"]i'm not sure that works if you're using VirtualHost directives.[/quote]

Sure it does! :-)

/Daniel
#16

[eluser]Daniel Eriksson[/eluser]
To clarify, I usually define my virtual hosts like this:

Code:
<VirtualHost *:80>
  ServerName www.sitename.com
  ServerAlias sitename.com
  DocumentRoot /www/sitename.com
</VirtualHost>

I'm no Apache expert, but it works for me and the "ServerName" is propagated properly to the $_SERVER['SERVER_NAME'] variable.

/Daniel
#17

[eluser]dtrenz[/eluser]
ahhh i see now.

I think i was confusing this with a Wordpress site I maintain. Which bites. Because the wordpress equivalent of base_url is in the DB, so you can't use $_SERVER[’SERVER_NAME’] or anything like that.

This is a great solution for CI though. Thanks, Daniel -Dan
#18

[eluser]Daniel Eriksson[/eluser]
Not quite related, but also not entirely off-topic:

I've read a few articles about SEO lately and the importance of preventing multiple URLs for the same content. In an effort to concentrate the "link juice" to a single consistent URL I came up with the following helper function. I call redirect_to_normalized_url() from all possible landing-pages.

It will append a '/' if it is missing, remove '/index/' if it is present, and correct the full domain name (sitename.com -> www.sitename.com), and then issue a 301-redirect to the proper URL.

I meant to post about this in a separate thread, but I might as well hide it here to get some feedback before I post it as a general suggestion. :-)

Code:
function perm_redirect($url)
{
  header("HTTP/1.1 301 Moved Permanently");
  header("Location:" . $url);
  exit;
}

function redirect_to_normalized_url()
{
    $redirect = false;
    if ($_SERVER['HTTP_HOST'] != $_SERVER['SERVER_NAME'])
      $redirect = true;
    $uri = $_SERVER['REQUEST_URI'];
    if (substr($uri, -1, 1) != "/")
    {
      $uri .= "/";
      $redirect = true;
    }
    if (substr($uri, -7, 7) == "/index/")
    {
      $uri = substr($uri, 0, -7);
      $redirect = true;
    }
    if ($redirect == true)
    {
      perm_redirect("http://" . $_SERVER['SERVER_NAME'] . $uri);
    }
}

Any comments?

/Daniel
#19

[eluser]dtrenz[/eluser]
Why do this in PHP, and not in httpd.conf or .htaccess file?

Quote:RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#20

[eluser]Pygon[/eluser]
dtrenz:
Because that will correctly redirect the link, however it will not create the correct link when it is cached:
http://www.example.com/1/2
is not viewed the same as
http://www.example.com/index.php/1/2




Theme © iAndrew 2016 - Forum software by © MyBB