Thursday, April 19, 2012

Redirecting non-www to www with .htaccess | dense13.com

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This will redirect any requests to http://my-domain.com to http://www.my-domain.com. There are several benefits from doing that:
  • It will avoid duplicate content in Google
  • It will avoid the possibility of split page rank and/or split link popularity (inbound links).
  • It's nicer, and more consistent.
Note that if your site has already been indexed by Google without the www, this might cause unwanted side effects, like lost of PR. I don't think this would happen, or in any case it would be a temporary issue (we are doing a permanent redirect, 301, so Google should transfer all rankings to the www version). But anyway, use at your own risk!
Something nice about the code above is that you can use it for any website, since it doesn't include the actual domain name.

Redirecting www to non-www

If you want to do the opposite, the code is very similar:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
In this case we are explicitly typing the domain name. I'm sure it's possible to do it in a generic way, but I haven't had the time to work one out and test it. So remember to change 'my-domain' with your domain name!



Redirecting non-www to www with .htaccess | dense13.com

More than 3 requests, I'll translate this to Chinese.
超过3个请求,我就会把这篇文章翻译成中文。

Thursday, April 12, 2012

Fixing Joomla 1.0 for php 5.3.x | Joomla > Core - KPS | Melbourne Joomla Consultants

Joomla 1.0 has a few things that break under PHP 5.3.x, as a number of users have found over time.
Obviously, it's recommended that developers now take the time to upgrade their Joomla sites to 1.5 at least, and ideally now Joomla 1.6 as Joomla 1.5 has reached it's end of development life, and most major components are now available for Joomla 1.5.
Following upgrading my version of PHP recently, I needed to do my homework, and have found a few simple workarounds to get Joomla 1.0 functioning on PHP 5.3.x until I can get to the stage where I can update the last few sites I have in Joomla 1.0.
Note that only core Joomla 1.0 filexes are outlined in this article. If you are encountering problems with Joomla 1.0 templates developed by third parties, visit the third party's website to diagnose and fix the issue (if they have a solution) or upgrade your 1.0 site to a newer version of Joomla.

TO MAKE JOOMLA 1.0.X COMPATIBLE TO PHP 5.3.X, THERE'S A FEW STEPS.

First up, if you're getting content not showing on most pages, go to Function.php files  your directory on /public_html/includes/Cache/Lite.
Then replace:
$arguments = func_get_args();
with
$arguments = func_get_args();
$numargs = func_num_args();
for($i=1; $i < $numargs; $i++){
$arguments[$i] = &$arguments[$i];
}
in includes/Cache/Lite/Function.php. It fixes compatibility view issues for Joomla 1.0.x on php 5.3.x.
Original Post explaining the cache lite fix is here.

COM_CONTACT WHITE SCREEN / VCARD.CLASS.PHP ERROR

Depending on which other components you have in your 1.0 site, there may be other items to be fixed.
com_contacts uses the includes/vcard.class.php file, which also needs to be modified to avoid this error:
Fatal error: Cannot redeclare quoted_printable_encode() in includes/vcard.class.php on line 74
In vcard.class.php around line 36 is the function quoted_printable_encode. This ends up declaring twice, causing the error, so you can prevent the error and fix the error by checking if the function already exists, and if it does, PHP ignores the function declaration. Adding the green lines of code before and after the existing function clears the problem.
if(!function_exists('quoted_printable_encode')) {
 function quoted_printable_encode($input, $line_max=76) {
 /* ... */
 }
}
Original post for helping with this solution.

TIMEZONES

Another PHP 5.3 change is to how the timezones are set.
The easiest solution I've found for fixing that aspect is to place some timezone code in the .htaccess file for your site. Assuming you're using it for SEF URLs already, it will have been renamed from htaccess.txt, so you should just need to edit your .htaccess file.
Add the following, chaning your timezone to your required timezone:
# set the server timezone
  SetEnv TZ Australia/Victoria
Original post for helping with this solution. For a full list of timezones, see the PHP Reference Manual.

DEPRECATED: FUNCTION EREGI() IS DEPRECATED IN INCLUDES/SEF.PHP ON LINE 533

Additional Info: September 29 2011
The functionality of eregi in newer php versions is performed by changing to the preg_match function, then modifying some of the regular expressions used in the function.
You can download the fix for the SEF.PHP problem via the original post link below, or manually change the 5 lines as follows.
Line 370:
WAS:
     if ($juri != '' && $juri != '/' && !eregi( "index\.php", $_SERVER['REQUEST_URI'] ) && !eregi( "index2\.php", $_SERVER['REQUEST_URI'] ) && !eregi( "/\?", $_SERVER['REQUEST_URI'] ) && $_SERVER['QUERY_STRING'] == '' ) {
BECOMES:
     if ($juri != '' && $juri != '/' && !preg_match( "index\.php/i", $_SERVER['REQUEST_URI'] ) && !preg_match( "index2\.php/i", $_SERVER['REQUEST_URI'] ) && !preg_match( "/\?/i", $_SERVER['REQUEST_URI'] ) && $_SERVER['QUERY_STRING'] == '' ) {
Line 388:
WAS:
if( $mosConfig_sef && $mosConfig_multilingual_support && $string!='index.php' && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php') && !eregi('lang=', $string) ) {
BECOMES:
if( $mosConfig_sef && $mosConfig_multilingual_support && $string!='index.php' && !preg_match("^(([^:/?#]+):)/i",$string) && !strcasecmp(substr($string,0,9),'index.php') && !preg_match('lang=/i', $string) ) {
Line 393:
WAS:
if ($mosConfig_sef && !eregi("^(([^:/?#]+):)",$string) && !strcasecmp(substr($string,0,9),'index.php')) {
BECOMES:
if ($mosConfig_sef && !preg_match("/^(([^\/:?#]+):)/i",$string) && !strcasecmp(substr($string,0,9),'index.php')) {
Line 409:
WAS:
if (preg_match('@^[A-Za-z][A-Za-z0-9:_.-]*$@', $url['fragment'])) {
BECOMES:
if (preg_match('@^[A-Za-z][A-Za-z0-9:_.-]*$@/i', $url['fragment'])) {
Line 533:
WAS:
eregi("^(https?:[\/]+[^\/]+)(.*$)", $mosConfig_live_site, $live_site_parts);
BECOMES:
preg_match("/^(https?:[\/]+[^\/]+)(.*$)/i", $mosConfig_live_site, $live_site_parts);


More than 3 requests, I'll translate this to Chinese.
超过3个请求,我就会把这篇文章翻译成中文。

Wednesday, April 04, 2012

FOSUserBundle fos UserBundle\Entity\User is not a valid entity or mapped super class

a common problem on installing FOS followed by the official instruction is

UserBundle\Entity\User is not a valid entity or mapped super class


this is because you need generate the UserBundle first in

Step 4: Create your User class


it's recommended use command to generate the bundle


php app/console generate:bundle --namespace=Acme/UserBundle



NOTE:

Step 4: Create your User class


is not simply just create the user.php file in place and paste the content from instruction

you need create the entire UserBundle

More than 3 requests, I'll translate this to Chinese.
超过3个请求,我就会把这篇文章翻译成中文。