apache tutorial - How to rewrite URLs in Apache with the mod_rewrite module - apache - apache web server - apache server - apache2


  • Apache's mod_rewrite module enables you to rewrite URLs. You can use URL rewrites in a number of scenarios, including:
    • Providing cleaner, more readable links to your web site. For example, instead of the URL http://www.example.com/products.php?id=232&cat=11, you could use the URL http://www.example.com/products/calculator instead with rewrites. In addition to making URLs more human-readable, they are also more search engine friendly, and can improve a web site's ranking and searchability.
    • Hiding the web site's internal implementation. Using the previous URL example, we can hide the fact that the site is using PHP, as well as mask queries that attackers could potentially use for malicious purposes.
  • To specify URL rewrite rules, you use directives such as RewriteRule and RewriteCond in an .htaccess file.
  • These directives rely heavily on regular expressions to provide URL pattern matching. There are many mod_rewrite options available, and describing all of them is beyond the scope of this article.
  • However, here is an example of a URL rewrite using the mod_rewrite module:
RewriteEngine on
RewriteRule ^products/calculator$ /products.php?id=232&cat=11
click below button to copy the code. By Apache tutorial team
  • In this example, visitors who use the URL products/calculators will actually view products.php?id=232&cat=11, though they will be unaware of this (the location bar in their browser still displays /products/calculators).
  • The RewriteEngine directive simply enables or disables URL rewriting, while the RewriteRule directive does the actual work of matching an incoming URL and specifying the target URL.

Related Searches to How to rewrite URLs in Apache with the mod_rewrite module

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.