roy naufal
roy naufal

Reputation: 389

rewrite rule php to non php not working

I have a read alot and this seems to be correct as to what i understand. I tried several different examples and scenarios, but it doesn't seem to work

I want to remove .php from these 2 files, and i am trying the below, but cannot figure out what's wrong, any ideas please?

RewriteCond %{HTTP_HOST} ^404\.php [NC] 
RewriteRule ^(.*)$ /404/ [L,R=301]

RewriteCond %{HTTP_HOST} ^recover-password\.php [NC] 
RewriteRule ^(.*)$ /recover-password/ [L,R=301]

thanks

Upvotes: 1

Views: 33

Answers (1)

anubhava
anubhava

Reputation: 785276

%{HTTP_HOST} cannot match your URL, it just matches host name part of URL.

Change your rules to this in root .htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+(recover-password|404)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L]

RewriteRule ^(recover-password|404)/?$ /$1.php [NC,L]

Upvotes: 1

Related Questions