How to create friendly URL in php?

后端 未结 8 1842
一整个雨季
一整个雨季 2020-11-21 11:06

Normally, the practice or very old way of displaying some profile page is like this:

www.domain.com/profile.php?u=12345

where u=12345

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 11:44

    I recently used the following in an application that is working well for my needs.

    .htaccess

    
    # enable rewrite engine
    RewriteEngine On
    
    # if requested url does not exist pass it as path info to index.php
    RewriteRule ^$ index.php?/ [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php?/$1 [QSA,L]
    
    

    index.php

    foreach (explode ("/", $_SERVER['REQUEST_URI']) as $part)
    {
        // Figure out what you want to do with the URL parts.
    }
    

提交回复
热议问题