• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Apache for Newbie: Enable mod_rewrite for URL rewriting

December 17, 2023

Apache for Newbie: Enable mod_rewrite for URL rewriting

As a newbie to the world of web hosting, you may have heard of Apache, the popular open-source web server software. One of the powerful features of Apache is the ability to rewrite URLs using the mod_rewrite module. This can be incredibly useful for creating user-friendly and search engine optimized URLs. In this article, we will explore how to enable mod_rewrite for URL rewriting on your Hong Kong VPS Hosting account.

What is mod_rewrite?

Mod_rewrite is an Apache module that allows you to rewrite URLs on the fly. It uses a rule-based rewriting engine to rewrite requested URLs based on various conditions. This can be useful for creating clean URLs, redirecting users to different pages, or even implementing custom error pages.

Why use mod_rewrite?

  • Clean URLs: mod_rewrite can help you create clean, user-friendly URLs that are easy to remember and share.
  • SEO: Search engines prefer clean URLs, and mod_rewrite can help improve your site’s search engine rankings.
  • Flexibility: mod_rewrite allows you to implement complex URL rewriting rules, giving you greater control over your site’s URLs.

How to enable mod_rewrite on your Hong Kong VPS Hosting account

Enabling mod_rewrite on your VPS hosting account is a straightforward process. Here’s how to do it:

Step 1: Check if mod_rewrite is enabled

Before you start, you need to check if mod_rewrite is already enabled on your server. You can do this by creating a simple PHP file with the following code:

<?php
phpinfo();
?>

Upload this file to your server and access it through your browser. Look for the “Loaded Modules” section and check if “mod_rewrite” is listed. If it is, mod_rewrite is already enabled, and you can skip to the next section.

Step 2: Enable mod_rewrite

If mod_rewrite is not enabled, you will need to enable it manually. You can do this by editing the Apache configuration file. On most hosting accounts, this file is located at /etc/httpd/conf/httpd.conf or /etc/apache2/apache2.conf.

Open the configuration file in a text editor and look for the following line:

LoadModule rewrite_module modules/mod_rewrite.so

If the line is commented out (starts with a #), remove the # to enable the module. Save the file and restart Apache for the changes to take effect.

How to use mod_rewrite for URL rewriting

Once mod_rewrite is enabled, you can start using it to rewrite URLs. Here’s a simple example:

RewriteEngine On
RewriteRule ^old-page.html$ new-page.html [L,R=301]

This rule will redirect users from old-page.html to new-page.html with a 301 redirect, indicating that the page has been permanently moved.

More complex examples

Mod_rewrite can also be used for more complex URL rewriting. For example, you can use it to create clean URLs for a blog:

RewriteEngine On
RewriteRule ^blog/([0-9]+)/([0-9]+)/([a-z0-9-]+).html$ blog-post.php?id=$1&month=$2&slug=$3 [L]

This rule will rewrite URLs in the format /blog/2021/03/my-blog-post.html to /blog-post.php?id=2021&month=03&slug=my-blog-post.

Conclusion

Enabling mod_rewrite on your Hong Kong VPS Hosting account is a simple process that can greatly enhance the functionality of your website. With mod_rewrite, you can create clean, user-friendly URLs that are also search engine friendly. Whether you’re a newbie or an experienced webmaster, mod_rewrite is a powerful tool that should not be overlooked.

Recent Posts

  • CentOS Server Performance Tuning: Optimization Techniques for 2026
  • How to Configure SELinux in CentOS Without Breaking Your System (CentOS Stream 9/10 – 2026)
  • Managing Users and Permissions in CentOS Stream: Best Practices (CentOS Stream 9/10 – 2026)
  • How to Set Up Nginx on CentOS Stream for High-Performance Web Hosting
  • CentOS Stream Explained: Key Differences from CentOS Linux

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot