- Locate and open your httpd.conf in a text editor
- locate this
section. - locate the line that reads ‘ AllowOverride None ‘
- Change it to ‘ AllowOverride All ’
- Restart Apache ’
Tag Archives: PHP
Block Hitbots – .htaccess
Paste the below given code into your .htaccess file
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://(www.)?phpcodezz.com.*$ [NC]
RewriteRule .* phpcodez.com [L]
Redirection By Language – .htaccess
Paste the below given code into your .htaccess file
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (en) [NC]
RewriteRule .* http://en.phpcodez.com [R,L]
Detect iPhone – .htaccess
Paste the below given code into your .htaccess file
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteRule .* http://iphone.phpcodez.com/ [R]
Show WordPress post attachments – WordPress
$args = array(
‘post_type’ => ‘attachment’,
‘numberposts’ => null,
‘post_status’ => null,
‘post_parent’ => $post->ID
);
$pczAttachments = get_posts($args);
if ($pczAttachments) {
foreach ($pczAttachments as $values) {
echo apply_filters(‘the_title’, $values->post_title);
the_attachment_link($values->ID, false);
}
}
Check if a page template is active – WordPress
Add the below given code in to your functions.php
global $wpdb;
$templateQry = “select meta_key from $wpdb->postmeta where meta_key like ‘_wp_page_template’ and meta_value like ‘Template1′”;
$result = $wpdb->query($templateQry);
if ($result) {
echo “page Template1 is active”
} else {
echo “page Template1 is not active”
}
Define a minimum word count in a post – WordPress
Add the below given code into your functions.php
function phpcodez_check_word($content){
global $post;
$num = 50; // set number of words required in a post
$content = $post->post_content;
if (str_word_count($content) < $num)
wp_die( __('The post does not have the minimum number of words') );
}
add_action('publish_post', 'phpcodez_check_word');
Set Default Language – .htaccess
You can set the default language of the browser by adding the below given code in your .htaccess file
DefaultLanguage en-US
Block requests with invalid characters – .htaccess
Add the below given code in your .htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9} [a-zA-Z0-9.+_/-?=&]+ HTTP/ [NC]
RewriteRule .* – [F,NS,L]
Block visitors by referrer – .htaccess
Add the below given code in your .htaccess file
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} referer_domain.com [NC]
RewriteRule .* – [F]
Note : Make sure that you have enabled the module “mod_rewrite” in your server