Not logged in. · Lost password · Register
Forum: General Help and Support Server Setup RSS
How to config 'non-www -> www' & 'http -> https' with htaccess
Avatar
lattekun #1
Member since Dec 2013 · 65 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to config 'non-www -> www' & 'http -> https' with htaccess
How to config url using htaccess?

1. Non-www -> www
  (ex : example.net -> www.example.net)
2. Http -> https
  (ex. http://www(or non-www).example.net/start
      -> https://www.example.net/start (not insert 'doku.php?id' in that link.))

Help me friends~~
Avatar
schplurtz (Moderator) #2
Member since Nov 2009 · 459 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
1. is solved with both DNS and web server setting. Usually, DNS names example.com and www.example.com resolve to the same IP. Then the webserver has to redirect example.com to www.example.com. This is an advanced configuration. I think, but I may be wrong, that it cannot be done in htaccess.
2. is a complex task that is not DokuWiki specific and that cannot be done in htaccess. The best is you ask your search engine and/or find some system administration forum dedicated to your system and webserver where you will get help. The helpdesk of your webhoster is probably a good starting point.

2bis "not insert 'doku.php?id' in that link." : Good news : This has nothing to do with protocol (HTTP/HTTPS). There is a dedicated page on DokuWiki Wiki. See https://www.dokuwiki.org/rewrite
Avatar
turnermm (Moderator) #3
Member since Oct 2009 · 4688 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
In reply to post #1
It's possible to rewrite http to https in .htaccess.  See https://www.elevated.com/guide-converting-site-http-https/
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

That's what I'm using for mturner.org.  As far as  can tell, it is working.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
lattekun #4
Member since Dec 2013 · 65 posts
Group memberships: Members
Show profile · Link to this post
Subject: Test your method...
1.
RewriteCond "%{HTTP_HOST}" "!^www\." [NC]
RewriteCond "%{HTTP_HOST}" "!^$"
RewriteRule "^/?(.*)"      "https://www.%{HTTP_HOST}/$1" [L,R,NE]

Result : http://aaa.net/start -> https://www.aaa.net/start

2. RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}/$1 [L,R=301,NE]

Result : http://www.aaa.net/start -> https://www.aaa.net/?id=start

If insert (.*) instead of ^
Result : http://www.aaa.net/start -> https://www.aaa.net/doku.php?id=start
Avatar
lattekun #5
Member since Dec 2013 · 65 posts
Group memberships: Members
Show profile · Link to this post
Subject: Finished.
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

## You should disable Indexes and MultiViews either here or in the
## global config. Symlinks maybe needed for URL rewriting.
#Options -Indexes -MultiViews +FollowSymLinks

## make sure nobody gets the htaccess, README, COPYING or VERSION files
<files ~ "^([\._]ht|readme$|version$|copying$)">
    <ifmodule mod_authz_core.c>
        Require all denied
    </ifmodule>
    <ifmodule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </ifmodule>
</files>

## Don't allow access to git directories
<ifmodule alias_module>
    RedirectMatch 404 /\.git
</ifmodule>

## Uncomment these rules if you want to have nice URLs using
## $conf['userewrite'] = 1 - not needed for rewrite mode 2
RewriteEngine on

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                        doku.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php

## Not all installations will require the following line.  If you do,
## change "/dokuwiki" to the path to your dokuwiki directory relative
## to your document root.
RewriteBase /dokuwiki
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-08-18, 05:23:49 (UTC +02:00)