How to Use .htaccess to Create Search Engine Friendly URLs

In this article, we will look at how you can use .htaccess to create search-engine-friendly URLs. We will use .htaccess to preserve your search engine rankings when moving your site to a new domain. We will also map dynamic pages to a static address, which search engines can better index.

Things You'll Need

  • computer
Show More

Instructions

    • 1

      Log in to your server and change to the directory where your Apache server stores its HTML documents. This is usually called "htdocs".

    • 2

      Create the file .htaccess by typing the command: "touch .htaccess". Don't forget the period in front of the file name.

    • 3

      Open the .htaccess file in your favorite text editor so that you can add new lines to the file.

    • 4

      To preserve search engine rankings when moving a page, add the following line to .htaccess: "redirect 301 oldpage.html http://mynewsite.com/newpage.html". This allows you to send users navigating to "oldpage.html" to your new site.

    • 5

      Redirect your entire web site to a new domain name or provider by adding the following line to ".htaccess: redirect 301 / http://mynewsite.com".

    • 6

      Use the rewrite-rule generator at this site to map your dynamic URLs to a static version: http://www.webmaster-toolkit.com/mod_rewrite-rewriterule-generator.shtml

    • 7

      Enter your dynamic URL at the above site and click "Generate RewriteRule". The generator will create a RewriteRule and display it in your browser.

    • 8

      Copy and paste the RewriteRule into your .htaccess file. Your dynamic page is now "spiderable" to search engines.

Tips & Warnings

  • In order to support RewriteRules, your Apache web server must support the mod_rewrite module. This can be configured in the main Apache configuration file and can be done by your Apache administrator.

  • You can do much more with .htaccess, including adding usernames and passwords to restrict access to your pages.

  • Make sure your .htaccess file is not world-readable or world-writeable. Only your user account should be able to edit the .htaccess file.

  • Many Apache installations allow users to browse directory indexes, enabling surfers to view all files in your directories. This can be a security problem. Prevent this by adding this line to your .htaccess file: IndexIgnore *

Related Searches:

Comments

You May Also Like

Related Ads

Featured