Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following url:

I want to rewrite it to:

I tried the following:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^topic/([a-zA-Z0-9]+)/$ index.php?topic=$1

Didn't do anything. I used a 3rd party website to generate this rewrite code so maybe it's incorrect, I dunno. Is there anything in Apache that could be causing this to not work?

share|improve this question
Where's that rule configured? – Shane Madden May 9 '12 at 3:41
Where's that final slash in the URL? – Ignacio Vazquez-Abrams May 9 '12 at 3:45
It's in .htaccess in the test directory along with the index.php. I don't know anything about missing a slash. That's why I'm asking the question in case something is wrong with the rule... – Jake Wilson May 9 '12 at 5:12
@Jakobud Your rule specifies a trailing slash. So, will never be rewritten, only will. Which behavior is needed? – Shane Madden May 9 '12 at 22:08

You're missing the /test/ in the URL. The leading ^ your rule means "start of path". You probably want:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/test/topic/([a-zA-Z0-9]+)/$ /test/index.php?topic=$1

Or something similar.

share|improve this answer
Oh, I suppose it matters where the rule lives. Possibly nevermind... – Bill Weiss May 9 '12 at 4:59
What if I wanted this to be path independent? What if I wanted it to work in /test/ or /test/whatever/ or /123/345/testing123/? – Jake Wilson May 9 '12 at 5:14
You could try something like ^/(.*)/topic/([a-zA-Z0-9]+)/$ /$1/index.php?topic=$2 (totally untested, sorry) – Bill Weiss May 9 '12 at 22:13

You cannot match the query string in RewriteRule, so you need to use RewriteCond.

RewriteCond %{QUERY_STRING} topic=(.*)
RewriteRule test/index.php test/topic/%1? [L]
share|improve this answer

Your Answer


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.