Les nouveautés et Tutoriels de Votre Codeur | SEO | Création de site web | Création de logiciel





seo URL Rewrite 2013

Seo Master present to you:

What are the benefits of rewriting URL?

Collected From: http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html

When a search engine visits the dynamic url like product.php?id=5 it does not give much importance to that URL as search engine sees "?" sign treat it as a url which keeps on changing. so we're converting the dynamic URL like the product.php?id=5 to static url format like product-5.html. We'll rewrite the url in such a way that in browser's address bar it will display as a product-5.html but it actually calls the file product.php?id=5. So that why these kind of URL also named as SEO friendly URL.

What is required for URL rewriting??

To rewrite the URL you must have the mod_rewrite module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter 500 Internal Sever Error.

How to check weather mod_rewrite module is enabled or not?
Data Collected: http://roshanbh.com.np/2008/04/check-enable-mod_rewrite-apache.html

Well there are lots of techniques to check this but I'll show you a very simple technique to check weather mod_rewrite module is enabled or not in you web server.

1) Type <?php phpinfo(); ?> in a php file and save it and run that file in the server.
2) And now you can the list of information, just search the word "mod_rewrite" from the browser's search menu
3) If it is found under the "Loaded Modules" section then this module is already loaded as you see in the picture below, otherwise you need to go to the next step for enabling mod_rewrite module.

How to enable mod_rewrite module in apache in xampp, wamp?

Now, I'll show you how to enable how to mod_rewrite module in apache installed under windows environment.
1) Find the "httpd.conf" file under the "conf" folder inside the Apache's installation folder.
2) Find the following line "#LoadModule rewrite_module modules/mod_rewrite.so" in the "httpd.conf" file.You can do this easily by searching the keyword "mod_rewrite" from find menu.
3) Remove the "#" at the starting of the line, "#" represents that line is commented.
4) Now restart the apache server.
5) You can see now "mod_rewrite" in the Loaded Module section while doing "phpinfo()".

Examples of url rewriting for seo friendly URL

For rewriting the URL, you should 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]

The following example will rewrite the test.php to test.html i.e when a URL like http://localhost/test.htm is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.

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

The following example will rewrite the product.php?id=5 to porduct-5.html i.e when a URL like http://localhost/product-5.html calls product.php?id=5 automatically.

Hiding PHP file extension

Collected From: http://roshanbh.com.np/2008/01/hiding-php-file-extension.html

Do you want to hide your web site's server script identity ? If you don't want to reveal the programming language ( server side script ) of your website to visitors of website so that any hacker or spammer will not be able to intrude or inject any code in your website.

Here is a small technique for you, you can use .html or .asp file to work as a php file i.e. use .asp or .html extension instead of .php. You just need to create a .htaccess file and put the following code in the .htaccess file. Remember that the .htaccess file should be placed in the root folder of your website.

# Make PHP code look like asp or perl code
AddType application/x-httpd-php .asp .pl

if you place the the above code in the .htaccess file then you can use contact.asp as the name of the file. Now a visitor thought that it is a ASP file but this file contains the codes of PHP.

You can put the following code in .htaccess file to work .htm or .html file as PHP file.

# Make all PHP code look like HTML
AddType application/x-httpd-php .htm .html


 

Redirecting www URL to non www URL

Data Collected From: http://www.9lessons.info/2009/01/htaccess-tutorials.html

If you type www.twitter.com in browser it will be redirected to twitter.com.


 


Add this Following Code:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.srinivas.com

RewriteRule (.*) http://srinivas.com/$1 [R=301,L]


 


 

Rewriting 'site.com/profile.php?username=foxscan' to 'site.com/foxscan'

My twitter profile http://twitter.com/foxscan its original link passing GET values (http://twitter.com/profile.php?username=foxscan) but this URL is ugly in browser address bar, For user friendly we can change like this.


 

If you want change like this see the below code

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1

RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1


 


 


 

This time I'm talking about rewriting second parameter URLs using .htaccess file.

Collected From: http://www.9lessons.info/2009/11/pretty-urls-with-htaccess-file.html


 


 


 


Original URL.
Eg. http://flickr.com/users.php?id=username&page=2

Rewriting Friendly URL.
Eg. http://flickr.com/username/2

.htaccess Code

//First Parameer
RewriteEngine On
RewriteRule
^([a-zA-Z0-9_-]+)$ users.php?user=$1
RewriteRule
^([a-zA-Z0-9_-]+)/$ users.php?user=$1

//Second Parameter
RewriteEngine On
RewriteRule
^([a-zA-Z0-9_-]+)/([0-9]+)$ users.php?user=$1&page=$2
RewriteRule
^([a-zA-Z0-9_-]+)/([0-9]+)/$ users.php?user=$1&page=$2


 


 


 


 


 


 

2013, By: Seo Master

Labels:



Leave A Comment:

Powered by Blogger.