的.htaccess:重写的.htm网址在内部.PHP,也重定向的.php网址为.htm [英] .htaccess: rewrite .htm urls internally to .php, but also redirect .php urls to .htm

查看:108
本文介绍了的.htaccess:重写的.htm网址在内部.PHP,也重定向的.php网址为.htm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP的网站。对于所有我用foo.htm,并在内部重写这foo.php使用.htaccess中的网页链接:

I have a php site. For all of the page links I use foo.htm, and internally rewrite this to foo.php with .htaccess:

RewriteRule ^(.*)\.htm$ $1.php [NC,L]

这个伟大的工程 - 然而,它仍然可以让你使用foo.php URL。我想301重定向foo.php从游逛foo.htm至prevent任何旧foo.php搜索引擎结果并重写内部的foo.htm网址foo.php

This works great - however, it still allows you to use the foo.php url. I would like to 301 redirect foo.php to foo.htm to prevent any old foo.php search engine results from hanging around and rewrite the foo.htm url internally to foo.php

我无法弄清楚如何做到这一点,而无需创建一个循环。

I can't figure out how to do this without creating a loop.

推荐答案

将这个code。在你的.htaccess文件:

Put this code in your .htaccess file:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{THE_REQUEST} ^GET\s(.+)\.php [NC]
RewriteRule ^ %1.htm [R=301,L]

RewriteRule ^(.*)\.htm$ /$1.php [L,NC]

这篇关于的.htaccess:重写的.htm网址在内部.PHP,也重定向的.php网址为.htm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆