Introduction
Url rewriting can be one of the best way to improve the usability and search friendliness of your site.
.htaccess rewrite module enable by using the Apche module mod_rewrite, which is one of the most powerful Apache module. Using mod_rewrite we can redirect request externally or internally.
What is URL Rewriting?
Most of the dynamic sites include variables in their URLs that tell the site what data show to the user. It looks like this:
http://www.yourdomain.com/show_a_product.php?product_id=7
The problems with this kind of URL structure are that URL is not at all memorable. It is also difficult to read out overphone. Search engine avoids this kind of url.
http://www.yourdomain.com/products/7/
This URL much easier to remember, than above one.
http://www.yourdomain.com/show_a_product.php?product_id=7
The problems with this kind of URL structure are that URL is not at all memorable. It is also difficult to read out overphone. Search engine avoids this kind of url.
http://www.yourdomain.com/products/7/
This URL much easier to remember, than above one.
Basic of URL Rewriting:
Step 1 : Enable mod_rewrite
Step 2 : Create .htaccess file and copy below code
RewriteEngine On
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Above code will redirect any non-existing page to your index.php
Above code will redirect any non-existing page to your index.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Above code force www in the URL.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L]
Above code rewrites a URL to another URL.
Above code rewrites a URL to another URL.
The following explains the rules above:
([0-9]+)allows any digit, and only any digit, 1 or more times.([a-z-]*)allows any lowercase letter, plus “-” for word separation, 0 or more times. If you want it to support uppercase too, use “([a-zA-Z-]*). For example:RewriteRule ^place/([a-zA-Z-]*).html /place/abc.php?id=$1 [QSA,L][QSA,L]appends this to your internal scripting query string, and makes it the Last rewrite rule executed.
Url Rewriting for beginners - BotNode
Reviewed by Snehal Vasava
on
May 24, 2018
Rating:
Reviewed by Snehal Vasava
on
May 24, 2018
Rating:

No comments: