Jeroen
Jeroen

Reputation: 31

Php block access without redirected .htaccess

With htaccess im redirecting:

RewriteRule ^secure/ login.php  [NC,L]

I only want people to be allowed to visit: website.com/secure/ But not: website.com/login.php

Anyone got an idea how to do this? Possibly in php?

Upvotes: 1

Views: 31

Answers (1)

anubhava
anubhava

Reputation: 784928

You can use:

RewriteEngine On

# block direct access to /login.php
# RewriteRule ^ - [F] line sends status 403 when RewriteCond succeeds.    
RewriteCond %{THE_REQUEST} /login\.php[\s?/] [NC]
RewriteRule ^ - [F]

# internally rewrite /secure to /login.php
RewriteRule ^secure/?$ login.php [NC,L]

First rule is using THE_REQUEST variable. THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules. Example value of this variable is GET /index.php?id=123 HTTP/1.1

Upvotes: 1

Related Questions