我有一个apache 2 PHP服务器,在公共html根文件夹中包含以下.htaccess文件:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]
</IfModule>
字符串
它包含一个RewriteRule,以便像这样重定向URL:
- http://example.com -> https://www.example.com
- https://example.com -> https://www.example.com
- http://www.example.com -> https://www.example.com
然而,我们注意到,当客户端在不使用www子域的情况下请求URL时,服务器会重定向到https/www URL,但会在URL的末尾添加.php扩展名,如下所示:
- http://example.com/page -> https://www.example.com/page.php
- https://example.com/page -> https://www.example.com/page.php
使用www子域请求url时不会发生这种情况:
因此,我认为Web服务器正在将文件扩展名添加到URL中,因为. htaccess中的RewriteRule。
有人可以帮助我编辑我的.htaccess文件,以便重定向停止在URL末尾添加.php文件扩展名吗?顺便说一下,服务器位于Cloudflare代理之后。谢谢你,谢谢
下面是.conf文件:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName {domain.com}
ServerAlias www.{domain.com}
ServerAdmin webmaster@{domain.com}
DocumentRoot /var/www/{domain.com}/public_html
<Directory /var/www/{domain.com}/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
#ci-dessous remoteip de cloudflare
RemoteIPHeader CF-Connecting-IP
ErrorLog ${APACHE_LOG_DIR}/{domain.com}-error.log
CustomLog ${APACHE_LOG_DIR}/{domain.com}-access.log combined
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} ={domain.com} [OR]
# RewriteCond %{SERVER_NAME} =www.{domain.com}
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/{domain.com}/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/{domain.com}/privkey.pem
AllowEncodedSlashes On
SSLProxyEngine on
<Location "/blog">
# Replace with your subdomain, https matters here https://ghost.org/help/apache-subdirectory-setup/
ProxyPass https://{blog-domain}/blog
</Location>
</VirtualHost>
</IfModule>
型
1条答案
按热度按时间zc0qhyus1#
为了更容易地排除故障(未测试),可能值得将重写规则分开。
字符串