vote up 0 vote down star
1

Hello, 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

flag

migrated from stackoverflow.com

2 Answers

vote up 2 vote down check

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|flag
Hey Gumbo, Thats great ! .k – Keet Sep 7 at 17:06
vote up 1 vote down

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

try:

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

Your Answer

Get an OpenID
or
never shown

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