views:

67

answers:

3

Hi,

I'm having problems working out how I can do the following using htaccess:

http://isitup.org/http://example.com => http://isitup.org/example.com

I think the problem is the second double slashes, but I can't think of a solution.

Here's my current (failed) attempt:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^http://([^/.]+\.[^/]+)/?$ /$1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+\.[^/]+)/$ /$1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+\.[^/]+)$ check.php?domain=$0 [QSA,L]

Thanks :)

A: 

If I remember correctly, the RewriteRule starts after the server information. So, in the URL http://www.server.com/path/to/file, a ^ will begin matching at /path/to/file.

So if you are creating URL's as you described above, you'd actually need to match the first /:

RewriteRule ^/http://([^/]*)/(.*)$ /$1/htdocs/$2 [R, NE]

That should provide you the ability to map the following:
http://isitup.org/http://example.com/path => http://isitup.org/example.com/htdocs/path

If you are providing virtual hosting, you might just consider using an Alias or a name-based VirtualHost instead.

jheddings
No; there's no leading slash on the URL portions `mod_rewrite` is matching against.
chaos
Hrm... All the mod_rewrite examples in the Apache docs start with the prefix `/` - http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteRule
jheddings
I thought `mod_rewrite` just acted on the request line, which would be `GET /http://example.com HTTP/1.1` in the OP's sample.
jheddings
Thanks, but again this doesn't work. As a note, I don't actually need the paths it may come with, only "example.com".
Sam
+1  A: 

Well, that pattern you're repeating should be ([^/]+\.[^/.]+), but that's only going to be important when DNS names with more than two elements show up.

Your main problem is probably that the last redirect should be to /check.php?domain=$1. Unless mod_rewrite is going to choke in general because that's not a valid W3C URL. But we can hope.

chaos
Thanks that makes sense, and I've corrected my errors. Unfortunatly the first rewrite still doesn't work.
Sam
+1  A: 

Test the original request line instead:

RewriteCond %{THE_REQUEST} ^GET\ /http://([^/\ ]+)
RewriteRule ^http:/ /%1 [R=301,NC,L]

The reason for that is that Apache removes multiple slashes in the request URL.

Gumbo
Ah so that's what was happening. Thanks a ton, it works a treat.
Sam
@Sam: You could just use something like this to see what’s arriving at the server side: `RewriteCond %{QUERY_STRING} ^$ RewriteRule .+ /?$0 [R]`
Gumbo