Forum Moderators: phranque
Im looking for some help to setup a htaccess like below:
Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www.aaa.com/
RewriteRule /* http://www.example.com/aaa [R,L]
RewriteCond %{HTTP_REFERER} ^http://www.bbb.com/
RewriteRule /* http://www.example.com/bbb [R,L]
RewriteRule ^(.*)\.html$ index.php?id=$1 [L]
I have the code above but no luck to do what I want. I need if the referer is aaa.com then it redirects to example.com/aaa, then if the referer is bbb.com it redirects to example.com/bbb, and finally if none of above are coming from aaa.com nor bbb.com it writes the friendly URL ( last line. )
It is working to redirect people based on the referer, but I cannot make it to work to re-write the URL for those not refered by aaa or bbb. It simple shows a 404 error obviously because the URL has not been re-written
Noticed that there is no error in the code (in fact it works when added to the domain root folder), but is not working at all when uploading the in a higher directory level. Surely, it is not able to re-write at this top level.
Example:
Placing it at
http://example.com/.htaccess
or
home/httpd/vhosts/example.com/httpdocs/.htaccess
it works fine
But placing it 1 or 2 levels above like:
home/httpd/vhosts/.htaccess
it doesnt work, even when apache reads all levels to find 1 htaccess before serving the page.
In fact, the aaa.com and bbb.com redirections work fine, just having problems with the rewrite when placing it at this level.
Unfortunately, I must place it there, so wondering if there is something I can add to the last line so it can rewrite the rule. May be like adding the example.com somewhere there, but Im frozen trying to get it (yea, googled almost every tutorial with no luck)
Hope someone here can help me out
[edited by: jdMorgan at 2:28 am (utc) on July 7, 2006]
[edit reason] example.com [/edit]
Look into converting your code for use in httpd.conf or conf.d.
Jim
P.S. You can make your rule more efficient by changing the pattern:
RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L]
However I noticed the htaccess placed above the domain root actually works, in fact placing it there it works when redirecting based on the referer, the part that is not working is the rewriting one, but the redir does.
May be htaccess works but which not is the rewrite thing
Anyway, is just an idea coz Im a newbie with this all stuff
Thanks
You cannot use .htaccess "above" the document root for a domain. By definition, it works in HTTP-accessible directories only.
Jim, I've been wondering about something related for a while. How about if a single .htaccess were placed in a directory housing numerous accounts, and then ScriptAliased (akin to some server-wide CGIs) to make it 'appear' in and be accessible to certain sub-directories?
/accountsdir
.htaccess
__ /account1
____ public_html
_______ .htaccess -> /dir1/dir2/accountsdir/.htaccess
Unauthorized eyes would still be blocked courtesy of httpd.conf:
<Files ~ "^\.ht">
Order deny,allow
Deny from all
</Files>
I ask because I could access accountsdir -- the server is co-located -- and uploading a single, revised, intentionally semi-global .htaccess would be easier than tweaking httpd.conf, and with no restarts.
Thoughts? TIA
I haven't tried the symlink approach, but it's worth looking into. Please let us known if you test it... :)
Jim
I found the htaccess privilegies "How directives are applied" at [httpd.apache.org...]
Further note that Apache must look for .htaccess files in all higher-level directories, in order to have a full complement of directives that it must apply. (See section on how directives are applied.) Thus, if a file is requested out of a directory /www/htdocs/example, Apache must look for the following files:
/.htaccess
/www/.htaccess
/www/htdocs/.htaccess
/www/htdocs/example/.htaccess
Hope it helps
I would guess that on your server, DocumentRoot is pointed "too high" in the filesystem, or that --as mentioned above by Pfui-- you may have a symlink or Alias directive at work here.
Jim
I tried some combinations like:
RewriteRule ^domain.com/httpdocs(.*)\.html$ index.php?id=$1 [L]
RewriteRule ^(.*)\.html$ [domain.com...] [L]
Thanks anyway
pd: yes, Im a newbie with all this stuff, jeje
Having "root access" is like having the Master Key to all of a server's locks. It's a big deal -- hackers try to "get root" specifically to take over machines.
If you're on a shared server, typically only your ISP's SysAdmin-level employees have root capability/responsibility and they should be highly disinclined to give any user root, sorry. (Being a passenger on a plane doesn't mean you also get to pilot it:)