.htaccess / redirecting to https://www.example.com and virtual folder access

穿精又带淫゛_ 提交于 2020-01-16 05:28:07

问题


I have a domain example.com. I want users to be redirected to https://www.example.com whenever one of the following is typed:

  • http://example.com
  • http://www.example.com
  • https://example.com

I also need to redirect people accessing /asdf (or /asdf/) to /index.php?folder=asdf.

I found some examples of code doing the first part, but there was always a debate about their effectiveness.


Edit: (need some more help! :))


回答1:


Try these mod_rewrite rules:

RewriteEngine on

RewriteCond %{HTTP_HOST} !=www.example.com [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

RewriteCond $1 !=index.php
RewriteRule ^([^/]+)/?$ index.php?folder=$1 [L]

But I recommend you to just allow one URL notation, the one with or without the trailing slash.



来源:https://stackoverflow.com/questions/1601876/htaccess-redirecting-to-https-www-example-com-and-virtual-folder-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!