WordPress subdomain rewrite rules for Zeus web server

If you have to deal with the Zeus web server, using WordPress subdomain, you most probably noticed that the “pretty” permalinks include “/index.php/” whatever you do.

You will need to create file named “rewrite.script” in the root directory where WordPress is installed – pretty much the equivalent to “.htaccess” in Apache.

Use this in your rewrite.sript and replace the domain URL with your own.



RULE_3_START:
insensitive match IN:Host into % with ^www.sub.domain.com
if  matched then goto RULE_2_END
RULE_3_END:

RULE_2_START:
insensitive  match IN:Host into % with ^(.*).sub.domain.com
if matched then match URL  into $ with ^/(.*)
if not matched then goto RULE_2_END
set URL =  /%1/$1
RULE_2_END:


RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}

# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
RULE_0_END:

RULE_1_START:
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

# check to see if the file requested is an actual file or
# a directory with possibly an index. don?EUR(TM)t rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
set URL = /index.php?q=%{SCRATCH:REQUEST_URI}
goto QSA_RULE_START
endif
endif

# if we made it here then its a file or dir and no rewrite
goto END
RULE_1_END:

QSA_RULE_START:
# append the query string if there was one originally
# the same as [QSA,L] for apache
match SCRATCH:ORIG_URL into % with \?(.*)$
if matched then
set URL = %{URL}&%{SCRATCH:QUERY_STRING}
endif
goto END
QSA_RULE_END:

After that you will need to go to the WordPress back-end and change your permalinks settings.

It might work with the main domain too – but I haven’t tested this.

Taxonomy Breadcrumbs

Add this function to the functions.php file in your current theme:

/* Taxonomy Breadcrumb */
function id_taxonomy_breadcrumb() {
// Get the current term
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
// Create a list of all the term's parents
$parent = $term->parent;
while ($parent):
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$parent = $new_parent->parent;
endwhile;
if(!empty($parents)):
$parents = array_reverse($parents);
// For each parent, create a breadcrumb item
foreach ($parents as $parent):
$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$url = get_bloginfo('url').'/'.$item->taxonomy.'/'.$item->slug;
echo '<a href="'.$url.'">'.$item->name.'</a> / ';
endforeach;
endif;
// Display the current term in the breadcrumb
echo $term->name;
}

And the call it in the temlate:

<?php id_taxonomy_breadcrumb(); ?>

Set WordPress permissions recursively with CLI in Linux

To easily change the permissions, just navigate to the WordPress install folder, and execute this two commands:

#Set all directories recursively to 755:
find . -type d -exec chmod 0755 {} +

#Set all files recursively to 644:
find . -type f -exec chmod 0644 {} +

If you are not in the current directory you will need to add the desired one after find, something like:

find /top/path/here -type d -exec chown www-data:www-data {} \;

PHP Mail Headers

Most MTA/MUA’s insert a lot of extra headers; however, here is sort of the bare minimum you can expect.

From: 
Reply-To:
To: 
Subject:
Date: date("r");
MIME-Version:
Content-Type:

If you using HTML, then you should probably be using multipart messages–but it’s not strictly necessary.

Here is a snippet of code that shows how multi-part mime headers can be assembled without the help of a mailer class.

<?
$mime_boundary=md5(time());
$headers .= 'From: My Email <me@company.com>' . "\n";
$headers .= 'MIME-Version: 1.0'. "\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"". "\n"; 
 
$msg .= "--".$mime_boundary. "\n";
$msg .= "Content-Type: text/plain; charset=iso-8859-1". "\n";
$msg .= "Content-Transfer-Encoding: 7bit". "\n\n";
$msg .= $textmessage . "\n\n";
 
$msg .= "--".$mime_boundary. "\n";
$msg .= "Content-Type: application/pdf; name=\"".$filename."\"". "\n";
$msg .= "Content-Transfer-Encoding: base64". "\n";
$msg .= "Content-Disposition: attachment; filename=\"".$filename."\"". "\n\n";
$msg .= chunk_split(base64_encode($doc)) . "\n\n";
$msg .= "--".$mime_boundary."--". "\n\n";
?>

Get the value from multiple checkboxes


<html>
<body>
<h3>Get Value from multiple checkbox in PHP</h3>
<form action="test.php" method="post">
<input type="checkbox" name="fruit_list[]" value="1">Apple 
<input type="checkbox" name="fruit_list[]" value="2">Banana 
<input type="checkbox" name="fruit_list[]" value="3">Mango
<input type="checkbox" name="fruit_list[]" value="4">Guava</br></br>
<input type="checkbox" name="fruit_list[]" value="5">Orange</br></br>
<input type="submit" value="Save" />
</form>
<body>
</html>
<?php
if(isset($_POST['fruit_list']))
{
$fruit_list = array();
foreach($_POST['fruit_list'] as $val)
{
$fruit_list[] = (int) $val;
}
$fruit_list = implode(',', $fruit_list);
echo "Fruits Value are :- ".''.$fruit_list;
exit;
}
?>

Redirect users/customers away from wp-admin

Use this code in the functions.php file for the active theme. Currently it will redirect users to /my-account – change as you like

add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() . "/my-account" );
exit;
}
}

Chroot sftp user/group directory.

This is a simple reference to chroot a sftp user or group to a folder – usually the web server folder. It is not covered “full” chrooting.

Edit /etc/ssh/sshd_config (/etc/sshd_config on some distributions) and set the following options:

#Subsystem sftp internal-sftp
#In some cases you might need to uncomment the line above and comment existing #Susbsytem option 
#Match user sftp-user
Match group sftp
ChrootDirectory /var/www
ForceCommand internal-sftp
AllowTcpForwarding no

Be sure to place the “Match” directive at the end of the file. This tells OpenSSH that all users in the sftp group are to be chrooted to their home directory (which %h represents in the ChrootDirectory command – you can use it instead of “/var/www” in this case), or any other you specify.

Don’t leave two or more Subsytem sftp directives at the same time – use only one. Otherwise you wont be able to access the server from ssh!

For any users that you wish to chroot, add them to the sftp group by using:

# usermod -G sftp paul
# usermod -s /bin/false paul
# chown root:root /home/paul
# chmod 0755 /home/paul

If you still have problems it is most probably because of directory permissions or/and ownership – you can try this:


sudo chown root /var/www
sudo chmod go-w /var/www
sudo mkdir /var/www/writeable
sudo chown bob:sftponly /var/www/writeable
sudo chmod ug+rwX /var/www/writeable

Be very careful as changes to sshd_config might leave you without ssh and sftp access to the server!!!