I am really struggling to understand how I can use htaccess / rewrite to change a url in the form www.domain.com/home/ to www.domain.com/index.php?route=home. I thought I cracked it, but the url shown in the browser also changed to show the query string. I wanted the displayed url to change along with rewrite.
I also wanted to redirect http to https. I see other websites achieve this (stackoverflow for example).
My current attempt is:
RewriteRule ^/?(w*?)/?$ https://www.%{HTTP_HOST}/index.php?route=$1 [R=301,NC,L]
2
Answers
Could you please try following. Written as per your samples. Also please clear your browser cache after placing these Rules into your .htaccess file. You are using
R=301
redirection which is why it changes the url to url of backend in browser itself, you don’t need it.When you have
http://
orhttps://
in target Apache will always send aR=302
flag to clients, forcing a full redirect.Here, you actually need 2 separate rules:
http -> https
Rewrite
rule toindex.php
for non-files and non-directoriesSuggested .htaccess:
Make sure to clear your browser cache before you test these rules.