Apache - Need to rewrite /contact/ to /contact.php
Solution 1:
# Internally rewrite "/contact/" to "/contact.php" RewriteRule ^/contact/?$ /contact.php [L]
In per-directory .htaccess
files you need to remove the slash prefix on the RewriteRule
pattern (as you have done on the earlier directives). So this should be written as:
RewriteRule ^contact/?$ /contact.php [L]
This matches requests for /contact
and /contact/
.
The slash prefix is not used on the RewriteRule
pattern because in a .htaccess
context, the directory-prefix (that notably ends with a slash) is first removed from the URL-path that the RewriteRule
pattern matches against. (The directory-prefix being the filesystem path of where the .htaccess
file is located.)