How to change .php file name

How can I change a file name like domain1.com/moreInfo.php to domain1.com/moreInfo

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

Then just update your links to point to the non .php version.

1 Like

Thanks for your reply.
However, I don’t understand where the domain1.com/moreInfo.php or domain1.com/moreInfo goes in that code.
Any additional clarifying would be greatly appreciated.

Plug that into your htaccess file please, then try going to a non .php version of the page.

Thanks for your reply.
Yes, that works. Thank you.
So, since it’s not specific to that page, it is there for all of my .php files?
Is there a way to make it specific to that one .php file?
Thanks again

One thing, I don’t know if it’s important or not. If someone adds a trailing slash this gives a 500 error.

@Gandalf, If someone adds a trailing slash, they’re asking for the DirectoryIndex file from the named directory. Per force, RR’s code will fail because it’s looking for a file.

@ChrisjChrisj, I would take exception to RR’s regex (in the RewriteRule but only because the ^ is misleading. To force a redirection, I will always use .? which apparently does the same thing but lets you know that the RewriteRule’s regex is looking for zero or more characters (always true so the redirection will always take place if the RewriteCond statements resolve to true. Okay, it’s merely a matter of preference but .? is easier to understand whereas ^ is simply a space filler.

Regards,

DK

@ChrisjChrisj if you only want to redirect one URL try something like

RewriteRule ^moreInfo$ moreInfo.php [L]

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.