Proventus
Proventus

Reputation: 35

How to forward the HTTP_REFERER to a page from htaccess?

When someone hits my site root folder (www.myDomain.com) and the Index.php page gets it after that, how can I forward HTTP_REFERER to the Index.php page so I can record it?

I have this but No Joy.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^mydomain.com [NC]
RewriteRule ^/?index.php?%{HTTP_REFERER}$ mydomain.com/ [L,R]

Thanks

Upvotes: 0

Views: 38

Answers (1)

danielson317
danielson317

Reputation: 3298

Make sure apache mod_rewrite is enabled. Then redirect with:

<IfModule mod_rewrite.c>
    # Make sure url's can be rewritten.
    RewriteEngine on

    # Redirect requests that are not files or directories to index.php.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>

This is how most CMS's do it. this does mean if they write the direct path to a file they will see that file. So you will want to precede this with something like:

# Prevent direct access to these file types.
<FilesMatch "\.(sql|md|sh|scss|rb|conf|rc|tpl(\.php)?|lib(\.php)?|wig(\.php)?|pg(\.php)?|reg(\.php)?|db(\.php)?)$">
  Require all denied
</FilesMatch>

This means that they can not access the file extensions listed above. You can replace the last few with just rc|php but I allow access to .php files not proceeded with .lib so I can do scripts protected by browser authentication for debugging and silver bullet database repairs.

You must also have something like this in your apache config that allows the .htaccess to be read in your sites directory.

<Directory "C:/Sites">
    AllowOverride All
</Directory>

Upvotes: 1

Related Questions