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 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.

/externalLink.php?url=http://example.com

I wnat this to be a nice url like /external/http://example.com

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

.k

share|improve this question

migrated from stackoverflow.com Sep 8 '09 at 3:21

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

2 Answers 2

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://

try:

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

 
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.