htaccess redirect subfolder .php file to trailing slash

107 Views Asked by At

I've tried all sorts of suggestions for .htaccess but nothing seems to work for some reason.

All i want is to redirect all of the .php files in http://www.pokertips.org/blog/ to a non-php ending. I've tried it with a .htaccess file in the /blog/ folder but still not working. I can get it to redirect so that it changes in the address bar, but it always results in a 404 error message.

For example: http://www.pokertips.org/blog/how-to-create-a-great-atmosphere-for-your-home-poker-game.php

redirects to

http://www.pokertips.org/blog/how-to-create-a-great-atmosphere-for-your-home-poker-game/

Also, just for reference, if anyone can tell me how it would work the other way around, i.e. a trailing slash redirecting to a .php ending, that would be useful too for another project.

Thanks in advance

1

There are 1 best solutions below

0
On

That's possible using QSA (Query String Append), see example below:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

Please see this post for more information

This should work for your subdirectory, Don't forget that you can lose the indexing of google if you change the URL of your pages.