Make Your Site Search Engine Friendly: mod_rewrite

free web hosting
Free Web Hosting > Computers & Tech > Search Engines > SEO Tools and Software Utilities

Make Your Site Search Engine Friendly: mod_rewrite

sid.calcutta
One of the most desired features of the modern websites are that the web-pages must be search engine friendly. The crawler must crawl through your webpages smoothly and can reach all the pages of your website as per your desire.

Creating a static link like
CODE
<a href="http://www.NewDomainName.com">My Home Page </a>
is still the best options as search engine bots can quickly pick-up such links. And you will definitely have a better chance of getting pages from your website indexed in major search engines.

But many of us are gradually moving from the days of static HTML pages to the dynamic pages and we have started using link like:

<a href="http://www.yourdomainname.com?action=search&category=jewelry">Click here to search for Jewelry </a>

Drawbacks of using dynamic pages:

Using dynamic pages, instead of age-old static HTML one, may give the impression to the search engine that the same page is being re-loaded. This fact has been mentioned in the Google's guide for webmasters.
Here is an abstrat of what Google says about it:

QUOTE
....... our crawlers may suspect that a URL with many dynamic parameters might be the same page as another URL with different parameters. For that reason, we recommend using fewer parameters if possible. Typically, URLs with 1-2 parameters are more easily crawlable than those with many parameters. Also, you can help us find your dynamic URLs by submitting them to Google Sitemaps.


For more details in this regard, please visit Google.com

Also it becomes difficult for the visitors of your website to read and type url containing too many partameters like

http://www.yourdomainname.com?action=search&category=jewelry etc. etc.


So we may employ a technique to chage the dynamically created links to look like a static one.
So a link like this:


CODE
http://www.yourdomainname.com?action = search&category=jewelry


will look like

CODE
http://www.yourdomainname.com/search/jewelry.htm



How is it accomplished? This is what mod_rewrite does for you.


Create a file named : .htaccess ( no file name please) and upload it in the root directory of your webserver.

The file will contain the moe_rewrite instructions for your webserver.
Here is the General Format of a typical .htaccess file.

RewriteEngine On
RewriteRule Pattern Substitution OptionalFlags


That file will contain the RewriteRules for your website. And whenever your webserver gets a request, it will check for the RewriteRules as written in your .htaccess file and then deliver the webpages as per instructions of the .htaccess file.

The structure of a RewriteRule
RewriteRule Pattern Substitution [OptionalFlags]

Let us explain what all these mean.

RewriteRule

This command tells the server that now we are going to state a mod_rewrite rule.

Pattern

A regular expression which will be applied to the “current” visible URL (i.e. http://www.yourdomainname.com/search/jewelry.htm)

Substitution

It tells the server how to substitute for the values it recovered from the current url. That is

CODE
http://www.yourdomainname.com/search/jewelry.htm


will be transformed to

CODE
http://www.yourdomainname.com?action = search&category=jewelry


OptionalFlags

This is the only part of the RewriteRule which isn’t mandatory.

Here is a model .htaccess file

CODE
RewriteEngine On
RewriteRule ^search/([^/\.]+).htm$ index.php?action=search&category=$1 [L]


Does it look bit ugly? Not at all, let us see how the server interprets it:

^search/
Directs the server to see whether the requested url starts with search/. If it doesn’t, this rule will be ignored.That is, this rule will track the url like

http://www.yourdomain.com/search/jewelry.htm,
http://www.yourdomain.com/search/pets.htm
http://www.yourdomain.com/search/blaa.htm


([^/.]+)
Here, the enclosing brackets signify that anything that is matched ( and appears after "/") will be remembered by the RewriteRule.
^/. => indicates that it will neither accept a "/" nor a period (.)
=> Whatever else it will get, it will remember that.
So, in our example, it will remember the word jewelry after reading the url

http://www.yourdomainname.com/search/jewelry.htm


$
This symbol indicates the end of string

Now the substitution part contains:

index.php?action=search&category=$1

The actual page which will be loaded by Apache. $1 is magically replaced with the text which was captured previously.

A special substitution is -. This substitution tells Apache to not perform any substitution.

[L]
Tells Apache to not process any more RewriteRules if this one was successful.


Now once you have created your .htaccess file, now you require to modify the links of your webpages in accordance with the new RewriteRules.

That is link like:

CODE
http://www.yourdomainname.com?action = search&category=jewelry


Will be changed to :

CODE
http://www.yourdomainname.com/search/jewelry.htm



To test your .htaccess file, you need to

Open the httpd.conf file and uncomment the following lines (remove the trailing #s):

CODE
#LoadModule rewrite_module modules/mod_rewrite.so
#AddModule mod_rewrite.c



I have shown here a basic example of mod_rewrite rule.

If you feel the need to mod_rewrite your website, then please visit doriat.com.




 

 

 


Reply

warallthetm
Interesting article. Would this parameter rule count if you only have one? Or dose google totally block all php parameters? I read in google that you cant have http://www.yoursite.com/?id=1&land=2 it says that you cant have a & after an id variable. Would it be ok if i did http://www.yoursite.com/?land=2&id=1 ?

Reply

sid.calcutta
QUOTE(warallthetm @ Jul 10 2006, 12:46 AM) *

Interesting article. Would this parameter rule count if you only have one? Or dose google totally block all php parameters? I read in google that you cant have http://www.yoursite.com/?id=1&land=2 it says that you cant have a & after an id variable. Would it be ok if i did http://www.yoursite.com/?land=2&id=1 ?


It is not a matter of blocking, rather, GoogleBOT does n't (or did n't) pick up those urls quickly. Not quite sure of their effect on Google SERPs as I have seen URLs like virtuemart.net/index.php?option=com_weblinks&catid=73&Itemid=4 appearing in SERP. Anyway, it is better to mod_rewrite the URLs instead of using multiple '&' in it.

 

 

 


Reply

lonebyrd
I've got a quick newbie question. Is using something like the <a href="http://www.yourdomainname.com?action=search&category=jewelry"> you mentioned, the best way to get google to see your website? I know with some of the other search engines (from what I hear) they use META tags. If so, I will definitly have to look into this mod-rewrite thing.

Oh, and one more question. Would you only have to do this to your main index page, or for every page on your website? Like I said, I'm a noob.

Reply

vujsa
QUOTE(lonebyrd @ Aug 7 2006, 10:49 AM) *

I've got a quick newbie question. Is using something like the <a href="http://www.yourdomainname.com?action=search&category=jewelry"> you mentioned, the best way to get google to see your website? I know with some of the other search engines (from what I hear) they use META tags. If so, I will definitly have to look into this mod-rewrite thing.

Oh, and one more question. Would you only have to do this to your main index page, or for every page on your website? Like I said, I'm a noob.


No, the best bay to get Googled PROPERLY is to use simplified URL's:
www.domain.com/search/jewelrt/index.html

It is harder for the bots, crawlers, and spiders to properly identify different pages when you use complex URL's:
www.domain.com/index.php?action=search&category=jewelry

This is because index.php is the file name so any other URL with that file name can be confused with the other so the bot may think it has already been done so it can skip that URL.

mod_rewrite is a very good way to ensure that your site is throughly indexed by the spiders but has a couple of problems associated with it.
  1. mod_rewrite requires the server to perform one additional step in the page load process which will eventually slow down your server and as a result your website when there is enough traffic.
  2. You have to format the URL's on your pages to the simplified type. Usuually this has to be done one at a time and manually unless you write a script to parse your pages prior to sending to the browser to convert the complex URL's to simplified URL's.
    - Then there is always the chance that you'll miss a rule for URL conversion.
    - - This could cause many problems in the page if done incorrectly.

I don't mean to be negative about this since I really like the Friendly URL method of SEO.

Hope This Helps. cool.gif

vujsa

Reply

pyost
QUOTE(vujsa @ Aug 7 2006, 07:03 PM) *
  1. mod_rewrite requires the server to perform one additional step in the page load process which will eventually slow down your server and as a result your website when there is enough traffic.
  2. You have to format the URL's on your pages to the simplified type. Usuually this has to be done one at a time and manually unless you write a script to parse your pages prior to sending to the browser to convert the complex URL's to simplified URL's.
    - Then there is always the chance that you'll miss a rule for URL conversion.
    - - This could cause many problems in the page if done incorrectly.


As for point number two, most people can easily bypass this problem. I suppose not many of you have created their own dynamic sites, but use Content Management Systems and Blog software. These types of web sites usually support additional components (modifications, hacks, call them whatever you want) that automatically deal with this topic. For example, Joomla! CMS and WordPress have mod_rewrite support by default, without any additions. I don't know about phpNuke, e107 etc.

Reply

sid.calcutta
QUOTE
Then there is always the chance that you'll miss a rule for URL conversion.


1.Usually mod_rewrite is employed for dynamic websites, where the links to different pages are generated from a backend database. So, if you can design the basic webpage and underlying datastructure to store the content in different categories, it will no longer be necessary to change each and every url manually. Only thing you should keep in mind is that you have mod_rewrite your website, so, the script generated links should look like
http://www.domainname.com/example_section_...xample_page.htm

2. It is easier to start designing a website keeping in mind the mod_rewrite factor from the vey beginning. But the reverse is really difficult as at times you may find it difficult to rewrite an existing url.

3. It takes hardly few hours to learn the basics of mod_rewrite, but it is really helpful to give the urls a better shape not only in terms of the search engine crawlers but also in terms of the visitors to your website who will find it much more comfortable to type the entire url instead of typing parameterised urls.

4. ALWAYS KEEP A BACKUP COPY OF YOUR EXISTING .htaccess file, as that is going to play the key role once you have implemented mod_rewrite. In case of any problem, simply restore the previous version.

Reply

Quatrux
I agree that mod rewrite is really cool, but for those who can't use htaccess files on their sites can choose an alternative to this, just use php, for example, you can also "fool" different crawlers and robots (etc.) and use links like this yourdomain.com/file.php/mysection/myid.html the string after .php can be get in the $_SERVER; superglobal 'PATH_INFO' so here is an example, if in a file file.php you would write this code:

CODE

echo $_SERVER['PATH_INFO'];


You would get "/mysection/myid.html" So you can do whatever you want with it, of course if you have htaccess, you can remove the usage of .php and use only file, the .php will be found automatically, but nevertheless, if you can use htaccess, better go with mod rewrite. wink.gif

Reply

jeffc
it is certainly a good strategy for SEO especially for Yahoo and MSN, the keywords in domain name is very important. Nowadays, a lot of CMS comes with this feature or there are a lot of plugins for it. For example, talking about the biggest CMS, Joomla, there are extensions such as opensef, sh404 that once you install them, you site will be a seo friendly site. For google, you may want to focus more on link building and social bookmarking sites

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. how to remove index.php from the sef url from sh404? - 101.92 hr back. (1)
Similar Topics

Keywords : make, webpages, search, engine, friendly, mod, rewrite, website

  1. Site Link Analyzer Tool
    (1)
  2. Additional Parameters In mod_rewrite URLs
    How to pass additional parameters in mod_rewrite urls (0)
    Hi everyboy, Oflate I faced great difficulty to pass additional parameters in mod_rewrite urls.
    I'll tell it from the beginning to help you understand exactly what was the problem. I have urls
    in my webpages which are like this one: CODE
    http://www.mydomainname.com/index.php?category=category_name And I wanted the url to look
    like this ( a more search engine friendly form): CODE
    http://www.mydomainname.com/category/category_name.htm So I applied mod_rewrite rule as per
    usual practice. CODE RewriteEngine On RewriteRule ^category/([^....
  3. Apache Tutorial: Enable mod_rewrite In Windows
    A brief action guide to enable mod_rewrite in Windows (2)
    Hi everybody, If you are using Windows OS and want to enable mod_rewrite module here is how to do
    it. This is the general configuration guideline both for Windows and Linux server: QUOTE 1. Find
    the httpd.conf file (usually you will find it in a folder called conf, config or something along
    those lines) 2. Inside the httpd.conf file uncomment the line LoadModule rewrite_module
    modules/mod_rewrite.so (remove the pound '#' sign from in front of the line) 3. Also find
    the line ClearModuleList is uncommented then find and make sure that the line AddModule mod_....
  4. Adding Search Feature To My Site
    (0)
    Hi, I'm looking for a script to add to my website. Either Perl/CGI or PHP will do. Just need
    to find one that's easy to customize. I looked around and found some but had problems with
    them. I have Google Search already but it's not exactly searching my whole site (probably
    because it didn't cache it yet). So I will most likely remove that search feature and add a
    better one that will do a more thorough search. Just a few things to mention. I read about this on
    one of the search script sites. So if anyone know of some search scripts that have these....
  5. Search Engine For My Site!
    (19)
    hi guyz. i have a site!! now i want to have a search engine on my site.... that wud
    ...give the user an option...to search the net....or my site!! to be frank....i dont know
    wats behind this..!! can ne body..temme..how to accomplish this!! Please temme
    links..tools....what ever (but it shud be free)!!....
  6. Search Engine Submission
    how to submit my site to search engine (26)
    hi, i don't know if my question ia appropiate here. 1. How can we submit our website to famouse
    search engines? yahoo, google, altavista, etc. 2. How to get higher ranking in those SE? thanks 4 ur
    time....

    1. Looking for make, webpages, search, engine, friendly, mod, rewrite, website

Searching Video's for make, webpages, search, engine, friendly, mod, rewrite, website
advertisement




Make Your Site Search Engine Friendly: mod_rewrite



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE