Home >Backend Development >PHP Tutorial >How to Ensure URL Rewriting Functionality with mod_rewrite?

How to Ensure URL Rewriting Functionality with mod_rewrite?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-22 21:10:031013browse

How to Ensure URL Rewriting Functionality with mod_rewrite?

Understanding mod_rewrite

mod_rewrite is an Apache module that enables URL rewriting, allowing you to customize request URLs to improve site functionality or SEO. It's crucial to understand that mod_rewrite is independent of PHP.

Enabling mod_rewrite

Windows

  1. Open the Apache configuration file httpd.conf located in:

    • Apache version 2.4: C:Program Files (x86)Apache Software FoundationApache2.4confhttpd.conf
    • Apache version 2.2: C:Program FilesApache Software FoundationApache2.2confhttpd.conf
  2. Add the following line:

    LoadModule rewrite_module modules/mod_rewrite.so

macOS/Linux

  1. Open the Apache configuration file httpd.conf or apache2.conf:

    • Ubuntu: /etc/apache2/apache2.conf
    • CentOS: /etc/httpd/conf/httpd.conf
    • macOS: /etc/apache2/httpd.conf
  2. Add the following line:

    LoadModule rewrite_module modules/mod_rewrite.so

Testing if mod_rewrite is enabled

  1. Create a .htaccess file in any web directory.
  2. Add the line:

    RewriteEngine on
  3. If the website loads without a "500 Internal Server Error" and .htaccess is parsed, URL rewriting is functional.

The above is the detailed content of How to Ensure URL Rewriting Functionality with mod_rewrite?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn