Reputation: 31
So I have the following stucture:
https://www.example.com
/index.html
/css
/images
/something
/else/with_subdirs
In each folder there could be index.html file
I want to convert all
http://www.example.com/dir1/subdir1?random_list_of_params
requests to
https://wwww.example.com/index.html?d=dir1&sd=subdir1&random_list_of_params
if dir1 or subdir1 do not exist.
This should be dome up to 3 levels deep aka
http://www.example.com/dir1/subdir1/subdir2/?random_list_of_params
https://wwww.example.com/index.html?d=dir1&sd=subdir1&sdd=subdir2&random_list_of_params
Please note dir1, subdi1 and subdir2 vary.
Thanks!
Upvotes: 1
Views: 240
Reputation: 133630
Could you please try following, written and tested with shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##For implying https to your all requests.
RewriteCond HTTPS !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
####For urls http://localhost:80/singh/singh1/singh2?testblabla
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ index.html?d=$1&sd=$2&sdd=$3&%{QUERY_STRING} [L]
##For urls http://localhost:80/singh/singh1?testblabla
RewriteRule ^([^/]*)/([^/]*)/?$ index.html?d=$1&sd=$2%{QUERY_STRING} [L]
##For urls http://localhost:80/singh?testblabla
RewriteRule ^([^/]*)/?$ index.html?d=$1&%{QUERY_STRING} [L]
Upvotes: 2