.htaccess htaccess子文件夹静默重定向基于多少子文件夹的url/link有

relj7zay  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(209)

我有以下情况
主网站https://www.example.com
我希望:
1.每个https://www.example.com/folder1/folder2/folder3/到静默重定向到https://www.example.com/folder1/index.php?d2=folder2&d3=folder3
1.每次https://www.example.com/folder1/folder2/folder3/folder4/到静默重定向到https://www.example.com/folder1/secondindex.php?d2=folder2&d3=folder3&d4=folder4
我在https://www.example.com/folder1/中创建了.htaccess文件
这是内容

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]+)/(.*)$ index.php?d2=$1&d3=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/(.*)$ secondindex.php?d2=$1&id3=$2&id4=$3  [L,QSA]
</IfModule>

问题是,对于这种类型的链接https://www.example.com/folder1/folder2/folder3/,它重定向ok到https://www.example.com/folder1/index.php?d2=folder2&d3=folder3,但对于第二种类型的链接,它不起作用。
我该如何修复它?

nqwrtyyt

nqwrtyyt1#

请使用您显示示例,根据您显示示例和尝试尝试尝试以下.htaccess规则文件

请确保:

  • 将.htacess文件放在folder1文件夹中。
  • index.phpsecondindex.php文件也存在于folder1中。
  • 在测试URL之前清除浏览器缓存。
RewriteEngine ON
RewriteBase /folder1/

##Internal rewrite for URL: https://www.example.com/folder1/folder2/folder3/folder4
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ secondindex.php?d2=$1&d3=$2&d4=$3 [QSA,L]

##Internal rewrite rule for URL: https://www.example.com/folder1/folder2/folder3/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/([^/]*)/([^/]*)/?$ index.php?d2=$1&d3=$2 [QSA,L]

相关问题