一些.htaccess问题

时间:2017-02-05 19:13:58

标签: apache .htaccess

首先,我是stackoverflow的新手,很抱歉,标题应该更具描述性。

我已经搜索并尝试了在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没有被正确重定向。例如,如果我输入"网站[dot] io"在地址栏中,它会重定向到" [https]://www.website.io" ;,所需的结果。但是,如果我键入" [http]://website.io"或者" [http]://www.website.io"或者" www.website [dot] io"它保留在HTTP中,我不想要它。有没有办法将流量重定向到HTTPS,无论它在地址栏中输入的方式是什么?

我的第二个问题是我想从网址中删除最后一个尾部斜杠,以防某人决定以这种方式输入。示例" [https]://www.site.io/register/"应重定向到" [https]://www.site.io/register"没有最后的斜杠。

非常感谢大家!

P.S。:我替换了一些" http(s)"用" [http(s)]"因为它不允许我发布链接。

1 个答案:

答案 0 :(得分:0)

要删除尾部斜杠使用:(未经测试,来自: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]

对于[括号]内的值,它可能会根据您的配置或需要而改变。