Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to convert the below url:

/letters.php?q=test&d=789&t=2

to:

/test/789/2

I tried something as below, but it did not work:

RewriteRule ^(.*)$ /letters.php?q=$1&d=$2&t=$3 [R=301,L]
share|improve this question
    
Your title and question body ask for opposite things. Please adjust one of them. –  John Gardeniers Dec 31 '12 at 9:39
    
Yes, I want to change the title. How can I do? –  Fun Jan 2 '13 at 4:01
    
Figured to changed the title :) –  Fun Jan 2 '13 at 4:06

1 Answer 1

up vote 1 down vote accepted

You would need to break up the RewriteRule extract each part of the uri i.e. test, 789 and 2; like this:

RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /letters.php?q=$1&d=$2&t=$3 [NC]

There is a good article on .htaccess tip and tricks that shows how rewrite rules work.

share|improve this answer
    
Thank you SubOracle!!! It works super!!!!! –  Fun Dec 31 '12 at 9:13
    
@Fun if this answer solve your problem, do not forget to accept it. –  j0k Dec 31 '12 at 9:44
1  
If you're going to be doing redirects for more than one page (ex: letters.php, words.php, etc) consider putting in a constant unique part to the URL like ^letters/([^/]+)/([^/]+)/([^/]+)$.... –  Tarek Fadel Dec 31 '12 at 10:29
    
Thank you jok! I am glad that you made me aware :) –  Fun Jan 2 '13 at 4:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.