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

Hey guys, how do I rewrite web requests of type where somenumber is an integer TO

like to

share|improve this question
it is actually the opposite buddy, you rewrite the rules to take directories and transform them into .php?id=15 an example would be, user request and the module will rewrite it to, to have the actual id you would do something like that would go for – Prix Aug 18 '10 at 1:04
Can you help me with that then? rewrite the "directory" to "mypage.php?id=15" – Daniel t. Aug 18 '10 at 1:52
up vote 2 down vote accepted

Yeah, well, assuming the comment on your question is what you in fact want, you would do something like:

Somewhere on apache's config:

LoadModule rewrite_module /usr/lib/apache2/modules/

On your .htaccess:

RewriteEngine On
RewriteRule ^/directory/$ /mypage.php?id=something [NE,PT]

This would make it so that when you open it would serve exactly the same content as

Edit: fixed typo on RewriteEngine and fixed the regexp too... was distracted.

Hope this helps you.

share|improve this answer
this one generated internal server error. – Daniel t. Aug 18 '10 at 1:51
Do you have mod_rewrite on your apache config? Something like LoadModule rewrite_module /usr/lib/apache2/modules/ Oh I see the problem now... editing answer :P RewriteEngine not Rewire hehe! – Khai Aug 18 '10 at 2:12
I could go for a "rewire" engine for apache! – warren Aug 18 '10 at 2:55
when tested, removing the / preceding directory seems to work RewriteRule ^directory/$ /mypage.php?id=15 [NE,PT] – Daniel t. Aug 18 '10 at 5:35
That makes sense. Since you're putting the RewriteRule in a .htaccess file the RerwiteBase (baseline for all rewritten URLs) is automatically set to the directory where the .htaccess is. Generally I put my RewriteRules on the vhost definition and I keep the preceding / for readability instead of setting RewriteBase. – Khai Aug 18 '10 at 10:52

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.