SSL .htaccess - 简单 Q [英] SSL .htaccess - Simple Q

查看:29
本文介绍了SSL .htaccess - 简单 Q的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很讨厌这个文件...我只花了 6.5 小时试图解决这个问题,而我的多动症阅读障碍是不可能的!!我有一个为 SSL 购买的域(目前我必须等待 ssl 才能启动 WWW,但现在没有 WWW 的域可以工作,例如:

I truly hate this file... I just spent 6.5 hours trying to figure this out and with my ADHD dyslexia it's just impossible!! I have a domain that I bought for SSL for (currently I Have to wait for the ssl for WWW to kick in but for now the domain without WWW works, for example:

https://tomas.com

我在 root 中拥有的 .htaccess 目前是:

The .htaccess I have in root is currently:

RewriteEngine On
RewriteCond %{HTTP_HOST} tomas\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://tomas.com/$1 [R,L]

上面的代码确实激活了 SSL,这很好.问题是,我在根域中有一些文件,但其中一个文件是:

And the code above does in fact activate SSL which is good. The thing is, I have a few files in root domain but one of them called is:

hello.php (位于:tomas.com/hello.php")

如果我去:http://tomas.com/hello我希望它显示该文件(并在地址栏中显示:http://tomas.com/hello").在 SSL 之前,我在下面有这个代码并且它有效(但不再有效):

If I go to: http://tomas.com/hello I want it to display that file (and in address bar it should say: "http://tomas.com/hello"). Before the SSL I had this code below and it worked (but not anymore):

RewriteRule ^([^/]*)/?(.*)$ $1.php

知道整个 .htaccess 应该是什么样子吗?:/

Any idea how the entire .htaccess is supposed to look like? :/

我也在同一时间试图强制它不使用 www(所以如果他们这样做应该被重定向到非 WWW url)预先非常感谢您!!!!!!!!!!!!

I'm also same time trying to FORCE it to NOT use www (so if they do it should be redirected to a non WWW url) Thank you so much in advance!!!!!!!!!!!!

推荐答案

在 SSL 之前,我在下面有这个代码并且它有效(但不再有效):

Before the SSL I had this code below and it worked (but not anymore):

RewriteRule ^([^/]*)/?(.*)$ $1.php

不确定这是如何工作"的;在此之前,它本身并不完整,它只是简单地附加一个 .php 扩展名.你需要一些东西来防止重写循环,因为 hello.php 也匹配模式 ^([^/]*)/?(.*)$.

Not sure how this "worked" before, it's not complete by itself and does more that simply append a .php extension. You need something to prevent a rewrite loop, since hello.php also matches the pattern ^([^/]*)/?(.*)$.

试试下面的方法,你的 HTTP 到 HTTPS 重定向之后.

Try the following instead, after your HTTP to HTTPS redirect.

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule (.*) $1.php [L]

在内部重写之前,这首先检查具有 .php 文件扩展名的文件是否存在.

This first checks that the file with a .php file extension exists before internally rewriting to it.

或者,如果您不进行任何其他 URL 重写,则可以改为仅启用 MultiViews.例如,在文件顶部:

Alternatively, you could instead just enable MultiViews if you aren't doing any other URL rewriting. For example, at the top of your file:

Options +MultiViews

这使用 mod_negotiation 基本上为一切启用无扩展名的 URL!

This uses mod_negotiation to basically enable extensionless URLs for everything!

这篇关于SSL .htaccess - 简单 Q的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆