open source guy
open source guy

Reputation: 2787

How access variable from url string using htaccess?

I have htaccess like this

RewriteRule i_am_(.*)_fan([0-9]).html$ /fans.php?player=$1&page=$2

When i enter url like this http://messi_fans.com/i_am_messi_fan2.html.it redirect to the page http://messi_fans.com/fans.php. But the GET variable is

Array ( [player] => messi_fan2 [page] => ) 

I want GET like this Array ( [player] => messi [page] =>2 ) How to modify above htaccess?

Upvotes: 0

Views: 44

Answers (3)

Felipe Alameda A
Felipe Alameda A

Reputation: 11799

Start by using at least the basic directives and some condition to prevent a loop, like this:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !fans\.php                        [NC]
RewriteCond %{REQUEST_URI}  ^/i_am_([^_]+)_fan([^.]+)\.html/? [NC]
RewriteRule .*              fans.php?player=%1&page=%2        [L]

Map silently

http://messi_fans.com/i_am_messi_fan2.html with or without trailing slash

To:

http://messi_fans.com/fans.php?player=messi&page=2

For permanent and visible redirection, replace [L] with [R=301,L]

Upvotes: 1

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

it should be

RewriteRule i_am_([a-zA-Z])_fan([0-9]).html$ /fans.php?player=$1&page=$2

Upvotes: 0

Waleed Khan
Waleed Khan

Reputation: 11467

You should use a lazy quantifier by appending a question mark to your .*:

i_am_(.*?)_fan([0-9]).html$

Upvotes: 0

Related Questions