Php 强制HTTPS同时删除文件扩展名

Php 强制HTTPS同时删除文件扩展名,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我一直试图在删除php扩展的同时强制使用HTTPS,但当我将两者混合使用时,我总是在浏览器上得到一个重定向循环 我在Stackoverflow周围搜索了一下,但只找到了一个具体的东西,而不是两个都有 这就是我目前拥有的: RewriteEngine on RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^

我一直试图在删除php扩展的同时强制使用HTTPS,但当我将两者混合使用时,我总是在浏览器上得到一个重定向循环

我在Stackoverflow周围搜索了一下,但只找到了一个具体的东西,而不是两个都有

这就是我目前拥有的:

RewriteEngine on 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteCond %{HTTPS} off
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]

这是我用来解决这个问题的方法

Options +FollowSymLinks -MultiViews
Options +Indexes
AcceptPathInfo Off
RewriteEngine on
RewriteBase   /

ErrorDocument 404 http://mysite.co.uk/404page/404.html

#Force from http to https
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{HTTP_HOST} !^mysite.co.uk$
RewriteRule ^(.*)$ https://mysite.co.uk/$1 [R=301]

#take off index.html
 RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]    

## hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]   

这是我用来解决这个问题的方法

Options +FollowSymLinks -MultiViews
Options +Indexes
AcceptPathInfo Off
RewriteEngine on
RewriteBase   /

ErrorDocument 404 http://mysite.co.uk/404page/404.html

#Force from http to https
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{HTTP_HOST} !^mysite.co.uk$
RewriteRule ^(.*)$ https://mysite.co.uk/$1 [R=301]

#take off index.html
 RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]    

## hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]   

@Switchfire-正在为重定向工作!谢谢。但如果url中有散列(#),则给出一些错误

所以我做了一些改变。而且也能做到 1.阻止直接访问目录 2.将www或非www请求重定向到


@Switchfire-正在为重定向工作!谢谢。但如果url中有散列(#),则给出一些错误

所以我做了一些改变。而且也能做到 1.阻止直接访问目录 2.将www或非www请求重定向到


为什么要重写cond%{SERVER\u PORT}80?这意味着该规则只有在其非HTTPS的情况下才有效;“那是打字错误吗?”伯汉哈利德,我的错,那部分是打字错误。谢谢你指出。你为什么要重写cond%{SERVER\u PORT}80?这意味着该规则只有在其非HTTPS的情况下才有效;“那是打字错误吗?”伯汉哈利德,我的错,那部分是打字错误。谢谢你指出这一点。