开发者

mod_rewrite / query_string

开发者 https://www.devze.com 2023-02-11 17:07 出处:网络
I get some basic results from a mysql database and list it on a page, on the page I\'ve added the links with the variable user_id:

I get some basic results from a mysql database and list it on a page, on the page I've added the links with the variable user_id:

href=\开发者_如何学编程"http://localhost/TESTING/template.php?user_id=$user_id\" >click here

On the template.php file I'll get the $user_id and display the relevant full data.

The thing is I don't want user_id=249 http://localhost/TESTING/template.php?**user_id=**249 to show in the url I'd like something like "http://localhost/TESTING/template.php/249".

I've been looking into this for a few days now with no success, is this possible? Or does the template file need the user_id=$user_id to be displayed in order to get the variable?

=====================

To update: I added the code

RewriteEngine On

RewriteBase /TESTING/

RewriteRule ^template.php/([0-9]+)(/)?$ template.php?user_id=$1 [L]

Changed the link variable to href="localhost/TESTING/template.php/{$user_id}" >click here

The re-write now works, but I'm not getting the variable with $user_id = $_GET["user_id"]; on the template.php page

I added the following to the template.php page to see whats being passed through the url:

<?php
ini_set('display_errors',1);
echo '<b>$_GET Variables</b><pre>';
var_dump( $_GET );
echo '</pre>';
?> 

and got the following response:

$_GET Variables

array(1) { ["user_id"]=> string(2) "21" }

How to get the variable?

===========

To update now works! {$user_id} in the link not {user_id} - could of swore i tried both ways.


Note that mod_rewrite only works on an Apache server.

RewriteEngine On

RewriteBase /TESTING/

RewriteRule ^template.php/([0-9]+)(/)?$ template.php?user_id=$1 [L]


I don't want to be inpolite, but there are a lot of manuals in the interwebs, e.g.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

which explains, with examples, everything you need. What have you tried so far? So we can explain what's wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消