user3312792 user3312792 - 1 month ago 9
PHP Question

mod rewrite single url .php

How can I rewrite a single URL with the code below?

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

Answer

You can change your regex pattern to make it target only home.php:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

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

RewriteRule ^(home)/?$ $1.php [L]