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

link|improve this question
feedback

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

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

2 Answers

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.

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

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

try:

RewriteRule ^external/(^http:\/\/.+)/$ /externalLink.php?url=$1 [L]
link|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
feedback

Your Answer

 
or
required, but never shown

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