Home > Backend Development > PHP Tutorial > How Can .htaccess Rewrite URLs for a Friendlier User Experience?

How Can .htaccess Rewrite URLs for a Friendlier User Experience?

Linda Hamilton
Release: 2024-12-10 22:51:10
Original
475 people have browsed it

How Can .htaccess Rewrite URLs for a Friendlier User Experience?

Creating Friendly URLs with .htaccess

Introduction

Creating friendly URLs can enhance the user experience and website aesthetics. .htaccess is a powerful Apache configuration tool that allows you to manipulate URLs. This article provides a comprehensive guide on how to create friendly URLs using .htaccess.

Creating the Base URL Configuration

To begin, create a .htaccess file in the document root of your website. Next, add the following configuration:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/([^/]+)/([^/]+)/?([^/]*)/?$ index.php?ctrl=&id=&tab= [QSA,L]
</IfModule>
Copy after login

This configuration will redirect all requests to index.php and pass the parameters in the URL query string.

Example URL Transformation

Let's consider an example URL transformation:

  • Before: http://website.com/index.php?ctrl=pelicula&id=0221889
  • After: http://website.com/pelicula/0221889/

**Handling Article

The above is the detailed content of How Can .htaccess Rewrite URLs for a Friendlier User Experience?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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