.htaccess - Prevent direct traffic to URL using htaccess -


i need prevent direct access url (http://www.example.com/gated-asset). there way add code htaccess file redirect direct traffic page (http://www.example.com/form)?

i have tried following code in htaccess file, pages, including home page, redirect www.example.com/form.

rewriteengine on  rewritecond %{http_referer} !^http://go.example.com [nc]  rewriterule .* http://www.example.com/form [r,l] 

the entire .htaccess file looks (it wordpress site):

# begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress  rewriteengine on  rewritecond %{http_referer} !^http://go.example.com [nc]  rewriterule .* http://www.example.com/form [r,l] 

i have tried following:

rewriteengine on rewritecond %{http_referer} !^http://go.example.com [nc] rewriterule ^/$ /form/ [r,l] rewriterule ^/$ /gated-asset/ [r,l] 

as as:

rewriteengine on rewritecond %{http_referer} !^http://go.example.com [nc] rewriterule http://www.example.com/gated-asset http://www.example.com/form/ [r,l] 

you need include http:// in referrer check if matching beginning (^). unlike http_host, http_referer requires it. in addition, referring url may include request_uri, , closing expression @ domain prevent working.

rewriteengine on  rewritecond %{http_referer} !^http://go.example.com [nc]  rewriterule .* http://www.example.com/form [r,l] 

if don't want include http://, can use following condition instead:

rewritecond %{http_referer} !go.example.com [nc] 

however, recommend first example used.

also included here r , l flags. r implied if rewrite external resource, better include it.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -