View Full Version : htaccess - redirect to a file without using full adress

04-26-2003, 03:05 AM
is that possible do redirect to a file/page/dir that located on same server, but dont use full path to it?
for example, this antileach code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/nasty.gif [R,L]
as u see it will redirect to http://www.yourdomain.com/nasty.gif but, I have different domains that point to same site, so, whenever some trying to leach it will show picture from one of domains.
so, is there a way use somesort of {HTTP_SELF}/nasty.gif or whatever that will use currently opened domain name?

also, where can I find more info about such a things, not just general info about .htaccess files, the more advanced info?


05-15-2003, 09:33 AM
Couldn't you just put additional lines like:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your2nddomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your3rddomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/nasty.gif [R,L]

05-15-2003, 10:32 AM
yep, that's the only way I know...
thought maybe there is different way to do same thing, with just one tag....ouh well.
thx fro the reply ;)

05-15-2003, 03:35 PM
Rewrite conditions and rules are regular expression patterns, so you should be able to do that.

Instead of the 3 conditions dragon wrote

RewriteCond %{HTTP_REFERER} !^http://(www\.)?(domain1|domain2|domain3).com/.*$ [NC]

05-15-2003, 10:41 PM
no, I dont have a problem to find out whitch domain in use, but the problem is to redirect to the same domain on the error page.
also, I have custom 404, 403 and 500 error pages but whatever domain in use it will redirect to whatever I specify, not to the same one...hope this is more clear now.

05-15-2003, 11:58 PM
No - less clear actually.

paint me a picture

05-16-2003, 12:17 AM
it's not about a picture, its not about the antileach (it was just an example ;))
ok, one more time:
1. I have several domains that point at the same IP, same site.
2. the site has custom error messages.
3. in .thaccess I have to specify the full address for the error document, right?
4. because of that I only can specify one address where the error document is, that cause that when error accur at another domain name (remmber it's same site, same document_root, same .htaccess, just different domain names) it will use document that points to the specific from the .htaccess error document. After that, the visitor has to either hit back button or continue surf at "new" domain name...

just to make it more clear the real example:
two different domains but same site.
now, lets try this, not existing document:
as u can see it opens error page but with the same domain name...
is there a way around it?
(I think it can be done in the apache http.conf file, but its not the case...)
btw, almost forgot to thank you for the replys ;)

05-16-2003, 02:56 AM
Oh - no, it's much simpler than that. This doesn't require url rewriting at all

ErrorDocument 404 /index.php?error=404

05-16-2003, 03:13 AM
well...I have tryed that before, it works only if the error acure in the root dir.
for exmaple, if the root is / and error acure in /something/here/ then it will try open error page not at root ( /index.php?error=404 ) but at current location ( /something/here/index.php?error=404 ) that become no ending cicle...

so, so far the only way I can think of is add for each virtualhost personal errordocument path...

05-17-2003, 04:54 AM
I seem to remember that you can give directories an alias, well think about it.
alias a folder for errors as in /error/
then when you reference it from whatever other folder it refers to the inline tree of folders it knows, since that is aliased it would know it as well.

Now I was also referencing this as basically in Apache. I have seen many references to doing this, but have not yet had a need for exactly this, so do not know how it is done.. but gives you something to look up...:thumbsup: