PHP Classes

MdRGen: Generate the definition of rules for mod_rewrite

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 3,294 This week: 1All time: 1,054 This week: 571Up
Version License PHP version Categories
mdrgenv 1Freeware4.0HTTP, Configuration, SEO
Description 

Author

This class can be used to generate the definition of configuration rules for rewriting URLs with mod_rewrite.

It takes a list of URLs of pages of sites before rewriting the URL.

The class generates a list of definition of rules to insert in .htaccess or other Apache configuration files to rewrite the URLs in a search engine friendly manner.

Innovation Award
PHP Programming Innovation award nominee
October 2007
Number 2


Prize: One book of choice by SAMS
mod_rewrite is a popular module for the Apache Web servers. It is often used to rewrite Web site page URLs to make them nicer and easier to type for the users.

Usually developers need to know how to create regular expressions to configure mod_rewrite.

This class provides an alternative solution to configure mod_rewrite that does not require knowledge of regular expressions. It simplifies the lives of those that want to benefit from mod_rewrite capabilities but do not have the skills to master the syntax of regular expressions.

Manuel Lemos
Picture of Viktor
Name: Viktor <contact>
Classes: 2 packages by
Country: Ukraine Ukraine
Age: 40
All time rank: 71414 in Ukraine Ukraine
Week rank: 420 Up7 in Ukraine Ukraine Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php
/*

    author: ivi
    email: ivi@newsroot.net
    www: http://newsroot.net

*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Rewrite Tools </title>

<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-language" content="ru">

</head>
<body>
<table border="0" cellpadding="0" cellspacing="0">
 
<tr>
    <td >
        <table cellspacing="0" cellpadding="0" width="100%" border="0">
            <tr>
              <td vAlign="top" height="100%" style="font-weight: normal; font-size: 12px; color: #000000"><b>
                  <b>Mod Rewrite rules generating Tool</b><br>
                  <span style="font-weight: normal; font-size: 12px; color: #000000">This tool helps you convert dynamic URLs into static looking html URLs.</span><br>
                  <br>
                 <b>How to use this tool</b><br>
                 <span style="font-weight: normal; font-size: 12px; color: #000000">
                  Step #1. Enter a URL (for sample http://newsroot.net/index.php?page=456&type=456&userid=56&item=8476). <br>
                  Step #2. You would need to create a file ".htaccess" and paste the code, Once you have created the .htacess file simply copy it into your web directory.
                 </span>
              </td>
     
            </tr>

        </table>
    </td>
</tr>
</table>

<form action="" method="post">
<table border="0">

    <tr>
        <td align="right" valign="top" style="font-size:80%; color:#ff0000;"><b>URL:</b></td>

        <td valign="top" align="left"> <textarea name="hosts"></textarea></td>
    </tr>
    <tr>

        <td align="right" valign="top"><b></b></td>
        <td valign="top" align="left"> <input name="submit" value="Generate" type="submit" /></td>
    </tr>

</table>
</form>


<?php
require_once("MRewrite.class.php");


if(
$_POST['hosts'])
{
   
$rewrite = new Rewrite($_POST['hosts']);
    if(
$rewrite->error)
    {
        die(
"Incorrect URL");
   
    }


?>
<table cellpadding="0" cellspacing="0" border="0">
<?php
           
           
/*********************************/
           
$arr = $rewrite->getType1();
           
           
           
           
//dump($arr);
           
           
           
$arr1 = $rewrite->getType2();
           
           
//dump($arr);
           
if(sizeof($arr) > 0)
            {
               
               
$html1 = "
                <tr>
                    <td colspan='2' valign='top' align='center'><b>Type 1 - Single Page URL </b></td>
                </tr>
                <tr>
                    <td colspan='2'>
                          Generated URL<br>
                         
$arr[fexpl]<br>
                          Create a .htaccess file with the code below<br>
                           The .htaccess file needs to be placed in
$rewrite->host
                    </td>
                </tr>
               
                <tr>
                   
           
                    <td valign='top' align='left' colspan='2'> <textarea cols='50' rows='10' name='type1' readonly>"
.$rewrite->getOut($arr)."</textarea></td>
                </tr>
                <tr><td height='10'></td></tr>
                <tr>
                    <td colspan='2' valign='top' align='center'><b>Type 2 - Directory Type URL </b></td>
                </tr>
                <tr>
                    <td colspan='2'>
                          Generated URL<br>
                         
$arr1[fexpl]<br>
                          Create a .htaccess file with the code below<br>
                           The .htaccess file needs to be placed in
$rewrite->host
                    </td>
                </tr>
               
                <tr>
                   
           
                    <td valign='top' align='left' colspan='2'> <textarea cols='50' rows='10' name='type1' readonly>"
.$rewrite->getOut($arr1)."</textarea></td>
                </tr>
   
               
                "
;
               
               
            }

            echo
$html1;
}
?>
</table> <br>

<center><a href="http://newsroot.net/projects/" style="color:black"><b>Powered by <b>News Root <span style="color:red">.NET</span></b></a></center>
</body>
</html>


Details

Class MdRGenv developer ivi E-mail: ivi@newsroot.net WWW: http://newsroot.net/projects/ ------------------------------------------------ Install: Copy MRewrite.class.php and index.php into your document root or your web folder. Open index.php from your browser. http://your.web.site.com/yourfolder/index.php

  Files folder image Files  
File Role Description
Accessible without login Plain text file index.php Example Sample
Plain text file MRewrite.class.php Class Main Class for rules generation
Accessible without login Plain text file readmy.txt Doc. ReadMe

 Version Control Unique User Downloads Download Rankings  
 0%
Total:3,294
This week:1
All time:1,054
This week:571Up
 User Ratings  
 
 All time
Utility:71%StarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:65%StarStarStarStar
Examples:81%StarStarStarStarStar
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1362