2017-02-05 56 views
-1

首先,我是新来的stackoverflow,很抱歉,如果标题应该更具描述性。一些.htaccess问题

我已经搜索并尝试了不同的解决方案张贴在这里stackoverflow但没有一个似乎解决我的具体问题。

首先,这里是我的.htaccess文件

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

RewriteRule ^hosting/?$ hosting.php [NC,L] 
RewriteRule ^premium/?$ premium.php [NC,L] 
RewriteRule ^register/?$ register.php [NC,L] 
RewriteRule ^auth/?$ login.php [NC,L] 
RewriteRule ^contact/?$ contact.php [NC,L] 
RewriteRule ^auth/forgot?$ forgot.php [NC,L] 
RewriteRule ^about/?$ about.php [NC,L] 
RewriteRule ^auth/activate?$ activate.php [NC,L] 
RewriteRule ^website/new?$ createwebsite.php [NC,L] 
RewriteRule ^profile/edit?$ editprofile.php [NC,L] 
RewriteRule ^auth/logout?$ logout.php [NC,L] 
RewriteRule ^privacy/?$ privacy.php [NC,L] 
RewriteRule ^profile/?$ profile.php [NC,L] 
RewriteRule ^auth/forgot/reset?$ resetPassword.php [NC,L] 
RewriteRule ^tos/?$ tos.php [NC,L] 
RewriteRule ^website/?$ websites.php [NC,L] 
RewriteRule ^website/manage?$ managewebsite.php [NC,L] 
RewriteRule ^website/manage/([A-Za-z0-9-]+)/?$ managewebsite.php?id=$1 [NC,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule ^(.*)$ https://www.website.io%1 [R,L,NC] 

我的第一个问题是,HTTPS未在某些情况下,适当地重定向。例如,如果我在地址栏中输入“website [dot] io”,它会重定向到“[https]://www.website.io”,这是所需的结果。但是,如果我输入“[http://website.io”或者“[http://www.website.io]”或“www.website [dot] io”,它会保留在HTTP中,我不会不想要。是否有办法总是将流量重定向到HTTPS,而不管它在地址栏中输入的方式如何?

我的第二个问题是,如果有人决定以这种方式键入,我想消除URL中的最后一个斜杠。示例“[https://www.site.io/register/”应该重定向到“[https]://www.site.io/register”,而不使用最后的斜杠。

非常感谢大家!

P.S .:我用“[http(s)]”替换了一些“http(s)”,因为它不会让我发布链接。

回答

0

要删除斜杠使用:(UN测试,从:Htaccess: add/remove trailing slash from URL

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

给力HTTPS使用:(我用的是什么,并与任何领域的作品)

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NC,QSA] 

对于值可以根据你的配置或需要而改变

+0

就像那样,我personnaly发现一些意想不到的行为,当有人试图访问一个实际存在的路径。充足的:如果你有一个名为phpClass的文件夹,并且有人试图访问example.com/phpClass,我的代码给了403,因为des目录存在,但没有索引。不知道如何(一段时间),但我通过为每个请求添加尾部斜线来修复它。 –