Ad

How To Use .htaccess To Do A Redirect From /login To /login/login.html

I'm trying to use .htaccess or any other method so that when a user types in

https://websitename/login

it will redirect to

https://websitename/login/login.html

I'm using apache2 on a debian 9.x server and have tried using mod_rewrite and RewriteRule. Neither are working.

Here is what I have currently:

RewriteOptions inherit 
RewriteEngine on
RewriteRule ^login$ "https\:\/\/websitename\.com\/login\/login\.html" [R=301,L]

any help would be appreciated. Thanks in advance :)

Ad

Answer

Since /login/ is an existent directory on your server, you need to trun off directory slash to redirect /login (without a traling slash) to /login.html .

RewriteEngine on

DirectorySlash off
RewriteRule ^login$ /login/login.html [L,R]

Clear your browser cache before testing this.

Ad
source: stackoverflow.com
Ad