Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 am trying to pass a actual url as a varible using mod_rewrite on apache

I have a page externalLink.php that can be passed a url in oder to do some magic i.e.


I wnat this to be a nice url like /external/

I have added a rewrite rule to my htaccess that I hope might work, but as a suspected it does not.

RewriteRule ^external/([^/.]+)/*$ /externalLink.php?url=$1 [L]

Does anyone know if this is possible ?

Thanks in advance


share|improve this question

migrated from Sep 8 '09 at 3:21

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

Try this rule:

RewriteCond %{THE_REQUEST} ^GET\ /external/(http://[^\ ]*)
RewriteRule ^external/http:/ externalLink.php?url=%1 [L]

You need to examine THE_REQUEST as Apache strips empty path segments in the URL path.

share|improve this answer
Hey Gumbo, Thats great ! .k – Keet Sep 7 '09 at 17:06

there will occur problems with the slashes in http://


RewriteRule ^external/(^http:\/\/.+)/$ /externalLink.php?url=$1 [L]
share|improve this answer
Following to your explanation, you forgot to escape the first slash in your regular expression. But that’s not necessary at all. This is not Perl or any other language where regular expressions have delimiters that need to be escaped. – Gumbo Sep 7 '09 at 16: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.