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
Release: 2024-10-22 21:10:03
Original
985 people have browsed it

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
    Copy after login
    Copy after login

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
    Copy after login
    Copy after login

Testing if mod_rewrite is enabled

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

    RewriteEngine on
    Copy after login
  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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template