重定向到https但没有.php [英] Redirect to https but without .php
本文介绍了重定向到https但没有.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我有一个https。我需要在.htaccess中重定向。我可以找到这个:
Now I have a https. I need a redirection in the .htaccess. I could find this:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
但我发现如果用户写道:
But I find that if the user writes:
http://myDomain/someFile
它重定向到:
https://myDomain/someFile.php
我认为正确的应该没有.php
怎么做?
I suppose that the correct should be without .php How to do that?
这些都是以下规则:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
推荐答案
这是您的问题的工作代码。我在我的服务器上检查了这个,它工作正常
here is the working code for your problem. I have checked this on my server, and it is working fine
RewriteEngine on
RewriteBase /
#for https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
以下是解释上述代码的链接 - 解释htaccess规则?
Here is a link for explanation of the above code - Explain htaccess rules?
这篇关于重定向到https但没有.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文