当前,我正在将.htaccess中所有对* .html的传入请求重写为* .php:
Currently I'm rewriting all incoming requests for *.html to *.php in my .htaccess:
RewriteEngine on RewriteCond %{HTTP_HOST} ^example\$ [NC] RewriteRule ^(.*)$ www.example/$1 [R=301,L] RewriteRule ^(.*).html$ $1.php [QSA] ErrorDocument 404 /404.html因此/something.html被重写为/something.php。
So /something.html is rewritten to /something.php.
但是/something.php仍然是在浏览器中直接访问。现在,当人们在浏览器中访问它时,我希望它重定向到/something.html,以便避免在同一页面的内容中使用2个不同的URL。
However, /something.php is still directly accessible in the browser. Now I want it to redirect to /something.html when people are accessing it in the browser, so as to avoid 2 distinct URLs for the same page of content.
是这可能在我的.htaccess文件中执行?怎么样?我尝试了R = 301,但它始终是重定向循环之类的东西。任何帮助,将不胜感激。谢谢!
Is this possible to do in my .htaccess? How? I tried R=301 but it's always a redirect loop or something. Any help would be appreciated. Thanks!
推荐答案将此内容添加到您的 RewriteRule ^(。*)。html $ $ 1.php [ QSA] 规则:
Add this above your RewriteRule ^(.*).html$ $1.php [QSA] rule:
RewriteCond %{THE_REQUEST} \ /(.+)\.php RewriteRule ^ /%1.html [L,R=301]将浏览器/客户端重定向到相同的请求,但使用 .html 而不是 .php 。
That will redirect the browser/client to the same request but with a .html instead of a .php.
更多推荐
301通过.htaccess将* .php重定向到* .html吗?
发布评论