user4128992
user4128992

Reputation:

HTACCESS redirect from subfolder to php file in subfolder

hello I have a website that includes an /admin folder in this folder I have a login.php file

How can I make it redirect the website.com/admin to website.com/admin/login.php using .htaccess inside the /admin folder ?

Upvotes: 1

Views: 1707

Answers (4)

Croises
Croises

Reputation: 18671

You can use only one RewriteRule with:

RewriteRule ^admin/?$ admin/login.php [NC,L]

Works with admin or admin/ or AdMin...

Upvotes: 0

anubhava
anubhava

Reputation: 785128

Inside /admin/.htaccess you can have this line:

DirectoryIndex login.php

This will load login.php if /admin/ is requested.

Upvotes: 1

maxhb
maxhb

Reputation: 8865

OK, this is even simpler and can be done like this:

RewriteCond %{REQUEST_URI} ^/admin$
RewriteRule .* http://yourhostname.tld/admin/login.php [L]

Just adjust the domain name to your needs.

Upvotes: 1

maxhb
maxhb

Reputation: 8865

Try this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* login.php [L]

This will redirect all request to login.php if 1) requested resource is not an existing file 2) requested resource is not an existing directory 3) requested resource is not an existing link 4) This will be the last redirect rule used

Upvotes: 0

Related Questions