使用.htaccess将URL子文件夹转换为参数



所以我有以下结构:

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、subd1和subd2各不相同。

谢谢!

请您尝试以下内容,并使用所示的示例进行编写和测试。请确保在测试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=$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]

最新更新