从.htaccess重写规则中排除.php

时间:2023-01-03 11:02:01

I currently have the following in my .htaccess file.

我目前在.htaccess文件中有以下内容。

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This works great, but i would like to exclude all .php files and have them serve up non-SSL pages. Can someone give me some help on how to achieve this please?

这很好用,但我想排除所有.php文件并让它们提供非SSL页面。有人可以帮我解决一下如何实现这个目标吗?

1 个解决方案

#1


Try:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .*(?!\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteRule \.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#1


Try:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .*(?!\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteRule \.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]