简体   繁体   中英

by using .htaccess file change the url parameter value

My htacess code is:

Options +FollowSymLinks

RewriteEngine on

RewriteBase /demo/kingstate/

RewriteCond %{THE_REQUEST} /detail\.php\?id=([^\s&]+) [NC]

RewriteRule ^ id/%1? [R=302,L]

RewriteRule ^id/([0-9]+)/?$ detail.php?id=$1 [L,QSA,NC].

my url changing from http://tinmandevserver.com/demo/kingstate/detail.php?id=1 to

http://tinmandevserver.com/demo/kingstate/id/1 by using a htaccess file but i want a url

like http://tinmandevserver.com/demo/kingstate/propperty-house-victoria .

this is first time i worked on htaccess code .

You cannot easily use mod_rewrite to perform a lookup from http://...?id=1 (or similar) to http://.../some-long-name unless you add one rule (RewriteRule line) for each number-to-name value pair.

Probably what you want to do is use PHP (and maybe SQL) to lookup the name given the number and then do a redirect. For example:

<?php
    $long_names = array('some-long-name','another-long-name');
    if (!empty($_GET['id'])) {
        header("Location: /demo/kingstate/".$long_names[$_GET['id']]);
        exit;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM