how to set up redirects by using .htaccess

To redirect a domain.com to www.domain.com

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

To redirect a subdomain sub.domain.com to www.newdomain.com

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^sub.domain.com [nc]
rewriterule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc]

Redirecting a website in PHP

<?php
header( ‘Location: http://www.domain.com/new_page.html’ ) ;
?>

You need to add provided code in your index.php file. it will be redirected to http://www.domain.com/new_page.html.

How to check if suexec enabled or not

You can use following steps to check the server for suexec

1) Login into you server as root and fire following command

#/usr/local/cpanel/bin/rebuild_phpconf --current

If server is Suexec then result would look like

DEFAULT PHP: 5

PHP4 SAPI: suphp

PHP5 SAPI: suphp

SUEXEC: enabled

2) If you are not sure about Shell then you can also check the SuExec is enabled or not? from your WHM.Lgin into your WHM and in the menu find Configure PHP and SuExec

Check the drop down box for “PHP 4/5 Handler” – and if beside that it says “suPHP” – Then your sever is SuExec enabled

3) If you don’t have root access, you can create a php file (test.php) in your account from cPanel >> File Manager and change the permissions on that file to 777 and open it in a browser. If it gives 500 Internal Server Error, your most probably running suPHP.

4)As well as you can also create the phpinfo page in your account from your cPanel >> File manager For ex. phpinfo.php with the following code;

<? phpinfo() ?>

After creating phpinfo.php page browse it http://yourdomainname.com/phpinfo.php and if it shows

Server API = Apache then server is not running PHP in Suexec mode

And if

Server API = CGI the server is running PHP in Suexec mode.

How to enable allow_url_fopen for a single domain in a cPanel server

The way to enable allow_url_fopen on a phpsuexec and a non-phpsuexec server is different. For security reasons the option is mostly disabled server wide, however, you can turn it ON for a single domain/account if it is required.

Its pretty simple to enable it.

On a non phpsuexec server:

# cd /usr/local/apache/conf/
see if you have a “userdata” directory there? If not, create the “userdata/” directory and then the file allowurl.conf inside it. So the complete path should look like:

# vi /usr/local/apache/conf/userdata//allowurl.conf
and add the following to the file
php_admin_value allow_url_fopen On
php_admin_value allow_url_include On

Now, edit the Apache configuration file and scroll down to the VirtualHost entry of the domain. Include the path of the above created file in it, as shown below:

Include “/usr/local/apache/conf/userdata//allowurl.conf”
Save the file and rebuild the apache configuration by

# /usr/local/cpanel/bin/apache_conf_distiller –update
# /usr/local/cpanel/bin/build_apache_conf
# /scripts/restartsrv httpd
This will enable allow_url_fopen for that domain.

On a PHPSuExec Or SuPHP server:
On a SuPHP enabled server, turning ON allow_url_fopen in the VirtualHost entry won’t work since PHP is not working as a Apache Handler anymore.

In such a case, copy the global php.ini of the server under directory of the domain, say public_html (you need to copy php.ini to the directory, where your script with allow_url_fopen resides)

# cp /usr/local/lib/php.ini /home//public_html/
Edit the new php.ini file and enable allow_url_fopen in it

allow_url_fopen = On
Save the file. That’s it.

please replace “” with the actual username of the domain wherever stated above.

PHP memory limit errors in wordpress

In wordpress, you may face PHP memory limit error and encounter following error,

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /home4/xxxxxx/public_html/wp-includes/plugin.php on line xxx

Such error is due to PHP Memory Limit set by the host, this value is set in server’s php.ini file . You  can overcome this issue by,

  • Increasing the limit via php.ini file

You can directly increase the PHP Memory Limit if you’ve access to the php.ini file. With some hosts, you may not have access to php.ini , in that case ask your host to copy php.ini file to your public_html folder or respective folder where wordpress is installed or you can create a file called php.ini. It can be set by editing value as

memory_limit = 64M

You can change the value as per your requirement.

  • Changing PHP memory limit in wp-config.php

If you don’t have access to php.ini file, alternative value can be set in wp-config.php. You need to edit wp-config.php and add following line after the <?php tag

define(‘WP_MEMORY_LIMIT’, ’64M’);

save the file and check.

  • Modification of the .htaccess file

This is alternative way, a very simple one.  You need to set proper value by editing .htaccess file as below.

php_value memory_limit 64M

  • Setting php memory value in install.php

This is yet another way to increase the PHP Memory Limit of your WordPress. There is an install.php file in the wp-admin folder of the WordPress installation.

All you should do is just add the command ini_set(‘memory_limit’,’64M’)in the install.php file. You will see the PHP Memory Limit increased.

  • Installing a wordpress plugin

If all above steps are not working, you can try installing proper wordpress plugin which monitors the memory usage or adds proper value in wp-config.php file (with 256MB limit) automatically and no need to edit the php file or set memory limit any where. Just install and activate it.

You can check the plugin here.