【问题标题】:Convert URL subfolders to parameters with .htaccess使用 .htaccess 将 URL 子文件夹转换为参数
【发布时间】:2021-04-18 03:13:39
【问题描述】:

所以我有以下结构:

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 不同。

谢谢!

【问题讨论】:

    标签: .htaccess redirect mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    您能否尝试使用所示示例进行以下、编写和测试。请确保在测试 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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-06
      • 2023-03-26
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 2020-01-23
      相关资源
      最近更新 更多