A
A
Alex2013-06-02 22:37:11
Regular Expressions
Alex, 2013-06-02 22:37:11

Help with htaccess regex

I want to redirect from an address like:
site.com/play/?t=title&l=link to site.com/title.html

I write:

RewriteEngine On
RewriteBase /
RewriteRule ^play/\?t=([a-z0-9-_]+)&l=[a-z0-9-_.:/]+$ $1.html [R]

But doesn't work :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2013-06-02
@BuriK666

use RewriteCond and %{QUERY_STRING}

E
elgordo, 2013-06-02
@elgordo

So just write a PHP script, your parameters are not contained in the path, but after the '?' sign.
index.php

<?php
$t=$_GET['t'];
$l=$_GET['l'];

include $t.".html";
?>

Usually mod_rewrite is used to convert a URL like site.com/title.html to site.com/play/?t=title&l=link , not the other way around.
As you've been told, you can indeed use %{QUERY_STRING} to pass script parameters, but I think that's pretty pointless.
ps Should be [a-z0-9_-]+ not [a-z0-9-_]+

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question