Add .html to the URL of WordPress Pages

There may be requirement to change the wordpress url. The permalinks options of wordpress maynot be sometime sufficient as per client specification. To get .html the post can be done by changing permalinks in admin , but adding .html extension in the page url is not done by it. For that just add the below lines in functions.php of your theme

add_action('init', 'html_page_permalink', -1);
register_activation_hook(__FILE__, 'active');
register_deactivation_hook(__FILE__, 'deactive');
function html_page_permalink() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
add_filter('user_trailingslashit', 'no_page_slash',66,2);
function no_page_slash($string, $type){
	global $wp_rewrite;
	if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
		return untrailingslashit($string);
		return $string;
function active() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
function deactive() {
	global $wp_rewrite;
	$wp_rewrite->page_structure = str_replace(".html","",$wp_rewrite->page_structure);

If you arenot intrested to do so then you can install this plugin from
Above code are also taken from the that plugin

If you want to get .php then then just change .html to .php on above code.

WordPress Permalinks on Windows IIS

Normally we host the wordpress site in linux hosting and everythings works fine with permalinks. But sometime server may be different , let say for the Windows IIS server the permalinks may not works hence resulting the URL that isnot SEO friendly. So to overcome this issue we need to create web.config in root directory and add the following code in the file.

<?xml version="1.0" encoding="UTF-8"?>
        <rule name="wordpress" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <action type="Rewrite" url="index.php" />
Source :

Magento Adding search by category in advance search

Sometime we may need to change the options provided by the magento by default. Here are dealing with adding the “Search By Category” in the advance search page. For this case we need to change in the followinf files
➣ app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php
➣ app/code/core/Mage/CatalogSearch/Model/Advanced.php
➣ app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml

At the very end of app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php (before the closing brace), add:

public function getStoreCategories()
    $helper = Mage::helper('catalog/category');
    return $helper->getStoreCategories();

In app/code/core/Mage/CatalogSearch/Model/Advanced.php, replace the getSearchCriterias() function (line 157) with the code below:

     public function getSearchCriterias()
            $search = $this->_searchCriterias;
            /* display category filtering criteria */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) {
                $category = Mage::getModel('catalog/category')->load($_GET['category']);
                $search[] = array('name'=>'Category','value'=>$category->getName());
            return $search;

replace the next function, getProductCollection(), with:

public function getProductCollection(){
        if (is_null($this->_productCollection)) {
            $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
            /* include category filtering */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['category']),true);
        return $this->_productCollection;

In app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml, after this code:

 <?php foreach ($this->getSearchableAttributes() as $_attribute): ?>
        <?php $_code = $_attribute->getAttributeCode() ?>
            <label for="<?php echo $_code ?>"><?php echo $this->getAttributeLabel($_attribute) ?></label>
            <?php switch($this->getAttributeInputType($_attribute)):
                case 'number': ?>
                <div class="range field-row">
                    <input name="<?php echo $_code ?>[from]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />
                    <input name="<?php echo $_code ?>[to]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text"/>
                <?php break;
                case 'select': ?>
                    <?php echo $this->getAttributeSelectElement($_attribute) ?>
                <?php break;
                case 'yesno': ?>
                    <?php echo $this->getAttributeYesNoElement($_attribute) ?>
                <?php break;
                case 'date': ?>
                    <?php echo $this->getDateInput($_attribute, 'from') ?>
                    <?php echo $this->getDateInput($_attribute, 'to') ?>
                <?php break;
                default: ?>
                <input name="<?php echo $_code ?>" id="<?php echo $_code ?>" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute)) ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text <?php echo $this->getAttributeValidationClass($_attribute) ?>" type="text" />
            <?php endswitch; ?>
        <?php endforeach; ?>


            <label for="category_search_field">Search by Category:</label>
            <select name="category" id="category_search_field">
                <option value="">-- Any Category --</option>
                <?php foreach ($this->getStoreCategories() as $_category): ?>
                <?php if($_category->hasChildren()): ?>
                <option class="parent-cat" value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php foreach ($_category->getChildren() as $subcategory):
                if($subcategory->getIsActive()) : ?>
                    <option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option>
                <?php endif; endforeach; ?>
                <?php elseif($_category->getIsActive()): ?>
                <option value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php endif; ?>
                <?php endforeach ?>

Then open app/code/core/Mage/CatalogSearch/Model/Advanced.php
Open the file and search this function addFilters. In this function you can see following codes, replace this

    if ($allConditions) {
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));

with following codes:

    if (($allConditions) || (isset($values['category']) && is_numeric($values['category']))) {
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));

After above steps is done you will get the output as below
search by category

Source :