article

Showing posts with label web-development (htaccess). Show all posts
Showing posts with label web-development (htaccess). Show all posts

Saturday, June 2, 2012

URL Mod_Rewrite PHP and htaccess

URL Mod_Rewrite PHP and htaccess

Download


#.htaccess
RewriteEngine On

# Check if the file or directory actually exists - if it does we dont want to redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Pass the rewritten URL onto index.php with a $_GET['url'] parameter
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
//index.php
<?php
$incommingURL = (isset($_GET['url']) ? $_GET['url'] : '');
 $url = array();
 // Split apart the URL String on the forward slashes.
 $url = explode('/', $incommingURL);
 switch($url[0]) {
  case 'home':
   include_once('home.php');
   break;
  case 'news':
   include_once('news.php');
   break;
  default:
   include_once('home.php');
   break;
 }
?>
//news.php
<h1>News</h1>
<a href="http://localhost/mod_rewrite/home/">http://localhost/mod_rewrite/home</a>

<h3>News Pages</h3>
<a href="http://localhost/mod_rewrite/news/page-1/">http://localhost/mod_rewrite/news/page-1</a><br>
<a href="http://localhost/mod_rewrite/news/page-2/">http://localhost/mod_rewrite/news/page-2</a><br>
<a href="http://localhost/mod_rewrite/news/page-3/">http://localhost/mod_rewrite/news/page-3</a>

<?php
 $pageNumber = (isset($url[1]) ? $url[1] : 'page-1');
 $page = explode('-', $pageNumber);
 echo '<h4>Page: '.$page[1].'</h4>';
?>

Tuesday, November 16, 2010

htaccess - Hide .php extension with url rewriting

htaccess - Hide .php extension with url rewriting

create a htaccess file in the root folder of your web directory. And have to put the following codes as your requirement.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]

Example
test.php to test.htm
http://localhost/test.htm

URL rewrite
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1

example
rewrite the product.php?id=5 to porduct-5.html
http://localhost/product-5.html
calls product.php?id=5


Tuesday, May 4, 2010

htaccess

.htaccess

.htaccess is a very ancient configuration file that controls the Web Server running your website, and is one of the most powerful configuration files you will ever come across. Htaccess is sometimes called: “HyperText Access” because of its ability to control access of the WWW‘s HyperText Transfer Protocol (HTTP) using Password Protection, Allow and Deny capabilities, and more.

Htaccess files use the default filename “.htaccess” but any unix-style file name can be specified from the main server config using the AccessFileName directive. The file isn’t .htaccess.txt, its literally just named .htaccess.

Creating Htaccess Files

Thursday, April 15, 2010

SEO Tools - URL Rewriting

SEO Tools - URL Rewriting

Static URLs are known to be better than dynamic URLs for a number of reasons:
Static URLs typically rank better in search engines.
Search engines are known to index the content of dynamic pages much more slowly than that of static pages.
Static URLs look friendlier to end users.

Example of a dynamic URL
http://www.yourdomain.com/profile.php?mode=view&u=7

Examples of the above static URL
http://www.yourdomain.com/profile-mode-view-u-7.html
or
http://www.yourdomain.com/profile/mode/view/u/7/





//example
//Method 1 - Single Page URL
//ex dynamic URL
//http://www.domain.com/profile.php?mode=view&u=7

//After converting your dynamic URL
//http://www.domain.com/profile-mode-view-u-7.html

//Create a .htaccess file with the code below
Options +FollowSymLinks
RewriteEngine on
RewriteRule profile-mode-(.*)-u-(.*)\.html$ profile.php?mode=$1&u=$2


//Method 2 - Directory Type URL
//ex. dynamic url
//http://www.domain.com/profile.php?mode=view&u=7

//After converting your dynamic URL
//http://www.domain.com/profile/mode/view/u/7/

//Create a .htaccess file with the code below

Options +FollowSymLinks
RewriteEngine on
RewriteRule profile/mode/(.*)/u/(.*)/ profile.php?mode=$1&u=$2


.htaccess: redirecting no www. to www.

.htaccess: redirecting no www. to www.

To redirect visitors from the www.-less domain we add the following code to our .htaccess file:



//Add the code to the .htaccess file

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

.htaccess: Disabling access to browse files on directories

.htaccess: Disabling access to browse files on directories

some website allow users to browse files on a particular directory on your website. Although this .htaccess files which will block access to browsing directories.

Download

http://dl.dropbox.com/u/3293191/htaccess/.htaccess





//Add the code to the .htaccess file
Options -Indexes

Related Post