Johnson Emmanuel
Johnson Emmanuel

Reputation: 121

htacess get the parameters

I am planning to create a channel like YouTube. So I want to extract the channel id and pass to MySQL using PHP. Can any one help me how to get the value (hope URL will remain same while redirect).

Here is the link: http://example.com/channel/UCIIIKudjRlpV9mdh9YOs0

Output page: example.com/channel/channelHome?channelid=UCIIIKudjRlpV9mdh9YOs0

$channelid = "UCIIIKudjRlpV9mdh9YOs0"

(but the URL to public remain same like below)

http://example.com/channel/UCIIIKudjRlpV9mdh9YOs0

I tried below code but did not work:

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^ /channel/?($1) 
RewriteRule ^ /channel/channelHome.php?channeid=$1 [QSA,L]

Upvotes: 1

Views: 77

Answers (1)

Gary Thomas
Gary Thomas

Reputation: 2331

You were close! You can use the following to convert the id to a query parameter:

RewriteRule ^channel/(.*) channel/channelHome.php?channelid=$1 [L]

This will keep the URL on the frontend:

http://example.com/channel/UCIIIKudjRlpV9mdh9YOs0

But allow you to access $_GET['channelid'] on the backend:

http://example.com/channel/channelHome.php?channelid=UCIIIKudjRlpV9mdh9YOs0

on the server side.


You can test it in action here: htaccess.madewithlove.be

Upvotes: 1

Related Questions