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?

closed as off-topic by Dhiren Vasoya, Mohit Kumar Arora, saravanavelu, Sukumar Gorai, Jai Mar 12 at 8:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced OR seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Dhiren Vasoya, Mohit Kumar Arora, saravanavelu, Sukumar Gorai, Jai
If this question can be reworded to fit the rules in the help center, please edit the question.


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

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

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