简体   繁体   English

通过使用.htaccess文件更改url参数值

[英]by using .htaccess file change the url parameter value

My htacess code is: 我的htacess代码是:

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/detail.php?id=1更改为

http://tinmandevserver.com/demo/kingstate/id/1 by using a htaccess file but i want a url 通过使用htaccess文件http://tinmandevserver.com/demo/kingstate/id/1 ,但我想要一个网址

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

this is first time i worked on htaccess code . 这是我第一次编写htaccess代码。

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. 您不能轻易使用mod_rewrite从http://...?id=1 (或类似名称)到http://.../some-long-name执行查找,除非您为每个规则添加一条规则(RewriteRule行)数字对名称值对。

Probably what you want to do is use PHP (and maybe SQL) to lookup the name given the number and then do a redirect. 可能您想做的是使用PHP(也许是SQL)在给定编号的情况下查找名称,然后进行重定向。 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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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