I have an URL like:


now when we click on this above URL then it should redirect to:


here we want to remove .php extension from URL after redirecting.

Note: we are clicking base_url/cloths/mens.php from Magento but base_url/wp/cloths/mens/ is post of WordPress.

We have written like:

Redirect 301 /cloths /wp/cloths

Here URL is redirecting properly but at the end of URL .php is getting append.

We have also tried this but didn't worked:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

How can we remove the .php part from the URL?


Found this,

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/cloths/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/cloths/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]  

Reference: Hide .php extension

| improve this answer | |
  • Tried suggested solution but not working. – groy Mar 11 '19 at 9:30
  • did you put it on the first line of your .htaccess from root directory of your magento ? – fmsthird Mar 11 '19 at 9:32
  • yes, tried multple suggested solution from stackoverflow also but non of them worked. – groy Mar 11 '19 at 18:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.