简体   繁体   English

htaccess 将子文件夹 .php 文件重定向到斜杠

[英]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.我已经尝试了 .htaccess 的各种建议,但由于某种原因似乎没有任何效果。

All i want is to redirect all of the .php files in http://www.pokertips.org/blog/ to a non-php ending.我想要的只是将http://www.pokertips.org/blog/中的所有 .php 文件重定向到非 php 结尾。 I've tried it with a .htaccess file in the /blog/ folder but still not working.我已经尝试使用 /blog/ 文件夹中的 .htaccess 文件,但仍然无法正常工作。 I can get it to redirect so that it changes in the address bar, but it always results in a 404 error message.我可以让它重定向,以便它在地址栏中发生变化,但它总是导致 404 错误消息。

For example: http://www.pokertips.org/blog/how-to-create-a-great-atmosphere-for-your-home-poker-game.php例如: 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/ 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.另外,仅供参考,如果有人能告诉我它是如何工作的,即重定向到 .php 结尾的尾部斜杠,这对另一个项目也很有用。

Thanks in advance提前致谢

That's possible using QSA (Query String Append), see example below:这可以使用 QSA(查询字符串追加),请参见下面的示例:

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.这应该适用于您的子目录,不要忘记如果您更改页面的 URL,您可能会丢失 google 的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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