i wanna make a redirect on my site. i've wrote a php-script like this: url.php if (@$_GET['url']) { header("Location: " . $_GET['url']); } else { die ("Couldnt read link"); } Code (markup): well, if i use link like http://mydomain.zone/url.php=http://forums.digitalpoint.com/ script will redirect me to this forum. but my link isnt pretty i want use http://mydomain.zone/url/http://forum.digitalpoint.com/ its better... i write in my .htaccess the command to rewrite url.php?url=$1 to ^url/(.+)$ Something like this: RewriteRule ^url/([a-zA-Z\:\/\.]+)$ url.php?url=$1 [L] or like this (more simple): RewriteRule ^url/(.+)$ url.php?url=$1 [L] I thought it will rewrite correctly, but it trims second slash after http:... Confused... why? if i use rule to make rewrite to the [R]ight and use link http://mydomain.zone/url/http://digitalpoint.com (enter to address in my browser) with rewriteRule: RewriteRule ^url/(.+)$ url.php?url=$1 [R] i'll get to http://mydomain.zone/url.php?url=http:/digitalpoint.com whats wrong and how to make it correct? Thanks in advance and sorry for my poor english ... )
RewriteEngine On RewriteCond %{REQUEST_URI} ^/url/((f|ht)tps?://(.+))$ RewriteRule . url.php?url=%1 [L] I've taken the liberty to add support for ftp and https urls too.
This is a weird one. I've never seen a backreference drop a slash like that before. You could try a more generic regex like in mortenb's example. (.+) instead of ([a-zA-Z\:\/\.]+) however his example won't work in a .htaccess file unless you remove the leading slash on the regex. It will work fine in an Apache conf file as it is. I have a suspicion that it might be the escaping of characters that don't need to be escaped that could be the problem. Maybe this: RewriteRule ^url/([a-zA-Z:/\.]+)$ url.php?url=$1 [L] Code (markup): It could be the PHP that is the problem rather than the Apache regex. It also occurred to me that we don't need the PHP in here at all if that is all it does. Try this one: RewriteCond %{REQUEST_URI} ^url/(.+)$ RewriteRule . %1 [R] Code (markup):
This is not true. It would have been true on a RewriteRule, but on a RewriteCond the leading slash is supposed to be there. Even in .htaccess.
Really ? I haven't actually ever tried a RewriteCond in a .htaccess before. I just don't use them. It makes sense though. The RewriteCond is acting on the variable %{REQUEST_URI} which has a leading slash but the RewriteRule is acting on the part of the URI that is relative to the location of the .htaccess file which is usually after /. (...and will always be after at least one slash.) I've learned something today.