简体   繁体   中英

htaccess redirect subfolder .php file to trailing slash

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, ie a trailing slash redirecting to a .php ending, that would be useful too for another project.

Thanks in advance

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM