KEMBAR78
Basicurlrewitinginphp | PDF | Career & Growth | Computers
0% found this document useful (0 votes)
112 views1 page

Basicurlrewitinginphp

This document discusses how to rewrite PHP URL query strings into cleaner, more search engine friendly URLs using the Apache mod_rewrite module. It shows how to take a URL like http://localhost/mytutorials/index.php?a=1&b=2&c=3 and turn it into http://localhost/mytutorials/1/2/3 by creating an .htaccess file with RewriteRule code that checks for the module, turns rewriting on, and redirects the query string values to the desired URL format.

Uploaded by

Sourabh Bhandari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views1 page

Basicurlrewitinginphp

This document discusses how to rewrite PHP URL query strings into cleaner, more search engine friendly URLs using the Apache mod_rewrite module. It shows how to take a URL like http://localhost/mytutorials/index.php?a=1&b=2&c=3 and turn it into http://localhost/mytutorials/1/2/3 by creating an .htaccess file with RewriteRule code that checks for the module, turns rewriting on, and redirects the query string values to the desired URL format.

Uploaded by

Sourabh Bhandari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

BASIC URL REWRITE WITH MOD_REWRITE

In this tutorial we will see how to rewrite php url query string like this:

http://localhost/mytutorials/index.php?a=1&b=2&c=3

You might have seen many of the urls like one above with lots of symbols and alphabets.
I'll show you how to make clean and search engine friendly URL out of this. We will
turn this link into:

http://localhost/mytutorials/1/2/3

To do this I'll use a module on apache webserver called module rewrite. We will create a
file named .htaccess and write the code shown below :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mytutorials/

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ index.php?


a=$1&b=$2&c=$3
</IfModule>

Now what this code does is: First it will check whether the module rewrite is present on
the server or not. If it is found then it will turn it on and set the base (base is basically the
root directory of the webfiles.). Then I have written the rewrite rule to convert the query
string into desired url. Here ^(carot) means the beginning of the url and $ means the end
of url. $1,$2,$3 means argument number 1,2 and 3 respectively.

© Sourabh Bhandari http://apnetutorials.co.cc

You might also like