dcolumbus
dcolumbus

Reputation: 9722

htaccess remove .php extension on specific file

I need to be able to rewrite a specific page so that the .php extension is removed:

http://www.mywordpresswebsite.com/my-landing-page.php

to:

http://www.mywordpresswebsite.com/my-landing-page
http://www.mywordpresswebsite.com/my-landing-page/

Again, I need to remove the extension for one file in particular, not every file.

Upvotes: 0

Views: 261

Answers (2)

Eduard
Eduard

Reputation: 1

For WordPress users that want to remove the extension for a specific file, make sure to include it before the index rewrite rule, so it can match it. This works to remove the .php extension from a specific file (validation.php) in a Wordpress Environment (note how I added the rule after <IfModule mod_rewrite.c>), making yourwebsite.com/validation works.

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteRule ^validation$ validation.php [L]
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Upvotes: 0

Leandro Bardelli
Leandro Bardelli

Reputation: 11578

EDIT:

RewriteRule ^web/?$ web.php  [NC]

Upvotes: 1

Related Questions