使用 .htaccess 将 URL 个子文件夹转换为参数
Convert URL subfolders to parameters with .htaccess
所以我的结构如下:
https://www.example.com
/index.html
/css
/images
/something
/else/with_subdirs
每个文件夹中可能有index.html个文件
我要全部转换
http://www.example.com/dir1/subdir1?random_list_of_params
请求
https://wwww.example.com/index.html?d=dir1&sd=subdir1&random_list_of_params
如果 dir1 或 subdir1 不存在。
这应该是最多 3 层深的圆顶
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
请注意 dir1、subdi1 和 subdir2 各不相同。
谢谢!
您能否尝试使用显示的示例进行以下、编写和测试。请确保在测试您的 URL 之前清除浏览器缓存。
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=&sd=&sdd=&%{QUERY_STRING} [L]
##For urls http://localhost:80/singh/singh1?testblabla
RewriteRule ^([^/]*)/([^/]*)/?$ index.html?d=&sd=%{QUERY_STRING} [L]
##For urls http://localhost:80/singh?testblabla
RewriteRule ^([^/]*)/?$ index.html?d=&%{QUERY_STRING} [L]
所以我的结构如下:
https://www.example.com
/index.html
/css
/images
/something
/else/with_subdirs
每个文件夹中可能有index.html个文件
我要全部转换
http://www.example.com/dir1/subdir1?random_list_of_params
请求
https://wwww.example.com/index.html?d=dir1&sd=subdir1&random_list_of_params
如果 dir1 或 subdir1 不存在。
这应该是最多 3 层深的圆顶
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
请注意 dir1、subdi1 和 subdir2 各不相同。
谢谢!
您能否尝试使用显示的示例进行以下、编写和测试。请确保在测试您的 URL 之前清除浏览器缓存。
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=&sd=&sdd=&%{QUERY_STRING} [L]
##For urls http://localhost:80/singh/singh1?testblabla
RewriteRule ^([^/]*)/([^/]*)/?$ index.html?d=&sd=%{QUERY_STRING} [L]
##For urls http://localhost:80/singh?testblabla
RewriteRule ^([^/]*)/?$ index.html?d=&%{QUERY_STRING} [L]