简体   繁体   中英

rewrite multiple php query with .htaccess parameters

site .com/ info rmation.php?country= usa &state= co &city= denver

to

site .com/ info / usa / co / denver

.htaccess

RewriteEngine On
RewriteRule ^info/([^/]+)/(.*)$/(.*)$ information.php?country=$1&state=$2&city=$3   [L]
RewriteRule ^info/([^/]+)/(.*)$ information.php?country=$1&state=$2                 [L]
RewriteRule ^info/([^/]+) informationl.php?country=$1                               [L]

information.php

<?php
echo $_GET["country"].'<br>';
echo $_GET["state"].'<br>';
echo $_GET["city"].'<br>';
echo $_SERVER['QUERY_STRING']'<br>';
?>

The first two query works fine but it wont catch the third one, well it does but it attach it to the 2nd query

usa

co/denver

country=usa&state=co/denver

I think im missing something, can anyone help me ?

You have two $ 's in there. This symbol means "end of the match", so you're "city" parameter is getting gobbled up by the "state" one. Try:

RewriteEngine On
RewriteRule ^info/([^/]+)/([^/]+)/([^/]+)$ information.php?country=$1&state=$2&city=$3   [L]
RewriteRule ^info/([^/]+)/([^/]+)$ information.php?country=$1&state=$2                 [L]
RewriteRule ^info/([^/]+) informationl.php?country=$1                               [L]

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